locked
Response.TransmitFile ignoring ContentType property RRS feed

  • Question

  • User-881099725 posted

    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.

     

    Sunday, September 9, 2007 8:47 AM

Answers

  • User437720957 posted

    You should add a content-disposition header as well.


    Response.AddHeader("Content-Disposition", "attachment; filename=thefile.zip")

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, September 9, 2007 12:16 PM