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

14,136

Solution 1

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

Solution 2

If you would add your page to the trusted sites you would be able to download the file. While developing all your sites you're running are in this zone.

You can try to force the internet explorer by adding

HttpContext.Current.ApplicationInstance.CompleteRequest();

to the end of your request.

Else you could try to post the link to the document, so the browser sees the request as a response of user interaction.

Share:
14,136
Boom Shaka Laka
Author by

Boom Shaka Laka

If you freeze my pay, I freeze my productivity. Its a vicious cycle.

Updated on June 18, 2022

Comments

  • Boom Shaka Laka
    Boom Shaka Laka about 2 years

    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.