IE 7 error? - invitation to save / open when downloading a file - C # asp.net 3.5

I have an aspx page with linkbuttons that run javascript to open a new aspx page to stream files to a browser for users to download.

When developing and unit testing on XP SP3, IE 7, and FireFox 3.5, using the following code (the key is part of the "attachment" in the Content-Disposition tag), both ask for a dialog box asking if I want to save or open the document, and that’s it I want:

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 go to the same aspx page, FireFox 3.5 sets the Save / Open parameter correctly, as expected, since this is the default operation in FF.

When I move to IE 7, but also load, I get a popup that is visible for the 1 / 8th second vertices ... and disappears. There is no hint to save / open.

If I go to IE 7 -> Tools -> Internet Options -> Security -> User Level -> Downloads

Automatic file download request is disabled. When I check it to enable i, you will get the Save / Open prompt correctly executed.

So my question is ... did anyone come up with a job for this? I tried a bunch of things that people require working with different header tags, such as cache, pragma, etc. Etc .... none of this is due to the fact that IE turned off the download property by default.

+7
c # internet-explorer-7 content-disposition
source share
5 answers

We recently encountered an identical issue with our implementation for loading generated reports in our user web environment. Research has led us to try to use the same approach you were talking about (setting up Content-Disposition).

The problem is with IE7 and security zones. By default, certain actions MUST be explicitly initiated by the user. You can start by viewing Understanding and Using Internet Explorer Protected Mode and About Window Limitations

+2
source share

If you add your page to trusted sites, you can upload the file. When developing all your sites that you use are in this zone.

You can try to get Internet Explorer to add

 HttpContext.Current.ApplicationInstance.CompleteRequest(); 

until the end of your request.

You can also try to publish a link to a document, so the browser sees the request as a response from user interaction.

+1
source share

Not related to this problem, but you need to specify the file name in your release. Spaces in the file name will screw the file name when loading the file.

 Response.AddHeader("Content-Disposition", "attachment;filename=\"" + filename + "." + m_format +"\""); 
0
source share

try it

protected void Button1_Click (object sender, EventArgs e) {Response.ContentType = "application / pdf"; Response.Clear (); Response.TransmitFile ("test.pdf"); Response.End (); }

0
source share

If you don't need to open a new page using javascript, you can use Response.Redirect () on the aspx page. This should open a save / open dialog.

0
source share

All Articles