Last post Sep 09, 2007 12:16 PM by gunteman
Sep 09, 2007 08:47 AM|degt|LINK
My ASHX handler serves ZIP files to make it simple. In the ProcessRequest after all the validation and data retrieval I set the context.Response.ContextType to "application/zip" which according to the net is the MIME type for .ZIP files.
After setting the content type I use the context.Response.TransmitFile(physicalPath) to stream out the ZIP file after doing all the other work.
However rather than the file being delivered as a known ZIP type you get the raw stream of the zip file. When using IE it gives an error saying it cannot serve XML (something like that) but looking more carefully you see it is actually complaining about the
"PK" invalid XML sequence. The PK is the file marker of ZIP files.
When using FireFox the behaviour is slightly different, it asks you if you want to download the ASHX file (!!!), if you choose to do so then it opens the file not as a recognized ZIP but as a binary file.
Does ContentType gets ignored by using Response.TransmitFile? I don't want to read the file in memory and then stream it out.
Sep 09, 2007 12:16 PM|gunteman|LINK
You should add a content-disposition header as well.
Response.AddHeader("Content-Disposition", "attachment; filename=thefile.zip")