Using the below code I am unable to show the open/save as file dialog:
public void ProcessRequest(HttpContext context)
{
string link
Finally figured it out. There is actually no problem with the code I posted. As you can see in the Fiddler output, the contents of the text file were successfully written to the response stream and the headers used were also correct. The actual problem comes from how the actual http request was made. I used a
$.get(urlToGenericHandler);
request using jQuery. The reason why specifically I am not able to download a file using AJAX or a callback model is beyond the scope of this answer. See supported jQuery datatypes here
Anyways, I changed the call from using AJAX to using a basic post-back.
Thanks to all that helped.
Try changing
contentType = "application/octet-stream";
to
contentType = "application/download";
Update: Try swapping the position of the header and content type
context.Response.AddHeader(
"Content-Disposition",
String.Format("attachment; filename={0}", fileName));
context.Response.ContentType = contentType;
context.Response.AddHeader(
"Content-Length",
new FileInfo(fullPath).Length.ToString());