In a code-behind I have a method that consists of the following:
Response.Clear();
Response.ClearHeaders();
Response.ContentType = "xxx";
Response.AppendHeader("Content-Disposition", "xxx");
Response.AppendHeader("Content-Length", xxx);
Response.BinaryWrite(xxx);
Response.Flush();
Response.End();
Now, this code will be used in a few different places. The code will be identical in the various places it is used. Only the file name and byte array will change and those are parameters passed to the existing method.
My question is, how do I pull this code out from the current code-behind and place it in a “Utilities” class. I tried copying and pasting the code into the class where I’d like it to reside by the Response object is giving me some problems (Cannot resolve symbol ‘Response’). I tried instantiating an HttpResponse to return but the constructor only takes a textwriter and upon further research, MSDN says I shouldn’t be doing that anyway.
Any suggestions?
Use
HttpContext.Current.Response, which will work in your Utilities.cs