17

I use ASP.NET with web forms, something that should be really easy is driving me crazy, similar questions have been asked but none of them helped me, IE refuses to download my files.

Things to notice:

  • I'm testing locally
  • It works in Firefox and Chrome but not IE11
  • IE changes file name to page's name (for example it tries to save default_aspx instead of myfile.pdf) File name changed enter image description here

This is my code:

Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "Application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.BinaryWrite(buffer);
Response.End();

These are the headers I got from IE:

Key Value

Response HTTP/1.1 200 OK

Cache-Control private

Content-Type Application/PDF

Server Microsoft-IIS/7.5

Content-Disposition attachment; filename=myfile.pdf

X-AspNet-Version 4.0.30319

X-Powered-By ASP.NET

Date Fri, 10 Apr 2015 22:44:40 GMT

Content-Length 691892

UPDATE

It seems like this is a server configuration issue because the same code will work fine in my production server but not in my development server. So my client won't complain about this, anyway I want to fix it in my development environment, as soon as I have time I'll investigate a little more, if I find a solution I'll post it here.

marcos.borunda
  • 1,379
  • 1
  • 15
  • 29
  • [IE 10 - File download issues](http://stackoverflow.com/questions/16655566/ie-10-file-download-issues), [“File couldn't be downloaded” in Internet Explorer with ASP.NET MVC](http://stackoverflow.com/questions/9609837/file-couldnt-be-downloaded-in-internet-explorer-with-asp-net-mvc). – CodeCaster Apr 13 '15 at 14:21
  • After downloading with Chrome, have you verified your content-length matches the actual size of your content? – Menno van den Heuvel Apr 14 '15 at 10:00
  • Have you tried using IE from another machine? The issue might be caused by certain settings of the browser. I found an article about previous versions of IE with the same problem: https://support.microsoft.com/en-us/kb/2549423 – Stamen Apr 15 '15 at 13:39
  • Could you provide a little information about how and when your Response code is being invoked? Is it an automatic response to a requested URL? Is it on a button click event? – cokeman19 Apr 18 '15 at 18:32
  • which exact version of IE are you using ?? – open and free Apr 20 '15 at 10:38
  • did any body resolve this? below answers did not resolve this – mzonerz Oct 23 '19 at 17:48

4 Answers4

5

We had a similar issue in ie8 the problem is that the file is searched in the cache and is not found. To test this please set Cache-Control : no-cache in your response object.

Mihai
  • 498
  • 4
  • 12
3

This is not the exact answer but hope if it can open some ways to find the exact one.

While googling I found this may be due to a security update release by Microsoft for IE.

Microsoft released a security update for IE11 on 8 Jul 14 which has a bug affecting the download.

And here is the Microsoft Connect Link that mention this under active status.

Please share exact solution once you find it.

Cheers!!

open and free
  • 2,097
  • 18
  • 22
2

I do something similar in my own app. Try removing the content-disposition header and change Application/pdf to application/pdf. You also likely don't need Response.End(), though I doubt that is what is causing the problem.

basher
  • 2,271
  • 1
  • 21
  • 34
  • 1
    If the problem isn't clear, you should refrain from answering. OP needs the content-disposition header, and the Content-Type header's value is case-insensitive. Use comments to ask for clarification instead. – CodeCaster Apr 13 '15 at 14:20
1

I have had similar issues in the past, I would try setting the response content length explicitly.

Response.AddHeader("Content-Length", buffer.Length.ToString())
user917170
  • 1,501
  • 15
  • 27