C# – IE 7 bug? – prompt save / open when downloading file – c# asp.net 3.5

asp.net-3.5ccontent-dispositioninternet-explorer-7

I have an aspx page with linkbuttons that fire javascript to pop open a new aspx page to stream files to the browser for downloading by users.

When developing and unit testing on XP SP3, IE 7 and FireFox 3.5, using the following code (key being the "attachment" part in the Content-Disposition tag), both prompt a dialog box asking if I want to save or open the document, which is exactly what I want to happen:

        private void WriteFileToBrowser(Byte[] requestFile, string filename, String m_mimeType, String m_format)
    {
        Response.Clear();
        Response.AddHeader("Content-Disposition", "attachment;filename=" + filename + "." + m_format);
        Response.ContentType = m_mimeType;
        Response.BinaryWrite(requestFile);
        Response.Flush();

    }

When I deploy this to a Windows 2003 server and navigate to the same aspx page, FireFox 3.5 correctly asks for a Save/Open option as expected since that is the default operation in FF.

When I navigate in IE 7 however and click to download, i get a pop up window that is visible for 1/8th second tops…and disappears. No prompt to Save/Open.

If i go into IE 7 -> Tools -> Internet Options -> Security -> Custom Level -> Downloads

Automatic prompting for file downloads is disabled. When i check it to enable i then get the Save/Open prompt to work correctly.

So my question is…..has anyone gotten a work around to this? I have tried a bunch of things people claim work with different Header tags such as cache, pragma, etc etc…none of that gets around the fact that IE has the download property disabled by default.

Best Answer

We ran into an identical problem recently with our implementation for downloading generated reports in our custom web framework. Research led us to trying the same approach you mentioned (setting Content-Disposition).

The problem is related to IE7 and security zones. By default, certain actions MUST be explicitly initiated by the user. You could start by looking at Understanding and Working in Protected Mode Internet Explorer and About Window Restrictions