I am dynamically generating a Zip file in an ASP.NET page and then sending the stream to Response. Pretty simple. In Firefox, I can download the file named "Images.zip" no problem. It works exactly as one might expect this to, so the code can't be too far wrong. In Internet Explorer 7 it tries to download a file called "ZipExport.aspx" or if it's in a Generic Handler, "ZipExport.ashx" and it says it cannot be found on the server and fails.
Here's my code:
Response.BufferOutput = true;
Response.ClearHeaders();
Response.ContentType = "application/octet-stream";
Response.AddHeader("content-disposition", "attachment; filename=Images.zip");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoServerCaching();
Response.Cache.SetNoStore();
Response.Cache.SetMaxAge(System.TimeSpan.Zero);
ZipFile zip = new ZipFile();
zip.AddFile(Server.MapPath("sample1.png"));
zip.Save(Response.OutputStream);
I'd rather not have to make an HTTPHandler for a certain file and have to register it with IIS. I am familiar with this though. Is there something simple I'm missing or is Internet Explorer at fault for ignoring my content-disposition header?
Edit: Moved code into ASHX page.
Response.Clear();
Response.End();
all great ideas, but no avail.
RECAP: I removed these lines and things worked:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Working code if anyone is interested:
public void ProcessRequest(HttpContext context)
{
context.Response.Clear();
context.Response.BufferOutput = false;
context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("content-disposition", "attachment; filename=ChartImages.zip");
context.Response.Cache.SetNoServerCaching();
context.Response.Cache.SetMaxAge(System.TimeSpan.Zero);
using(ZipFile zip = new ZipFile())
{
zip.AddFile(context.Server.MapPath("sample1.png"));
zip.Save(context.Response.OutputStream);
}
context.ApplicationInstance.CompleteRequest();
}