The name 'response' does not exist in the current context

Im using the following snipet

httpContext.Current.Response.Clear();
        string FileName = Server.MapPath("/downloads/Resume.doc");
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" & FileName);
Response.Flush();
Response.WriteFile(sSourceUrl);

I can't seem to find much info on the response object, primarily the basis behind the error: The name 'response' does not exist in the current context

Steve7423Asked:
Who is Participating?
 
vinodhsomasekharanConnect With a Mentor Commented:
Hai Steve,

I hope u r using C#.

The HttpContext is available in  the namespace System.Web.So try,

using System.Web;

HttpContext.Current.Response.Clear();

I hope u have used -- httpcontext.current.response.contexttype

I think the case is wrong... Try giving..

HttpContext.Current.Response.Clear();

just replace Response with  HttpContext.Current.Response and try..


Hope this helps u,

Regards
Vinu



0
 
apb2Commented:
Hi Steve

Why are you flushing the buffers before you write the source

string FileName = Server.MapPath("/downloads/Resume.doc");
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" & FileName);
Response.WriteFile(sSourceUrl);
Response.Flush();

Try that

apb2
0
 
Steve7423Author Commented:
I changed the flush as you stated.  I suspect the problem is an object reference.  does the response object require declarations?

Ive tried httpcontext.current.response.contexttype and the httpcontext comes up with the same error.

I'm taking this method from other posts on EE as well as out of a book.  unfortunately things aren't explained well.

0
 
apb2Commented:
I bet it's nothing to do with the response object and more to do with whate ever this is "sSourceUrl"

Could you post the code where you implement this?

and no the response object won't need any implementation as such

apb2
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.