0

Prelminary Conclusions It is likely the local copy of the installed browser (ie9) was the issue. The same solution file version worked on another developer's computer. I will reinstall my browser on monday. I think the browser either got corrupted or had settings changed. When I run previous versions of the source control, the same problem appears long before it was an issue.

The version on the dev server (non-local copy) actually works with my browser, but it recognizes my browser in the response header as "Mozilla 4/ie7 compatiable". However, my local copy was recognizing my browser as "Mozilla 5/ ie9 compatible" I'll further update this question when/if the local browser is confirmed as the problem. ( This question may no longer be relevant or helpful to anybody but we can wait a bit to close it - if its closed early that is okay too as the solution will likely be too localized to help anybody)


Original Text

Ie9 is failing to download my file, the browser receives it, but doesn't display it to the user.

It still works infirefox, but it recently broke in ie9 when I made my pages use ajax.

Some code from my controller is below

    public ActionResult FileDownload(string id)
    {
          //[ommitted some code]                      
          var fp = FileProvider.GetFileContentFromDisk( fileLocInfo.FilePath);
          var stream = new MemoryStream( fp.Data );
          return File( stream, fp.MimeType, fileLocInfo.FileName );
    }

File is sent, but fails to display for download

Ah, the question is what code can I use to provide a file for download to the user that will work in older browsers.

I've tried Context.Reponse.BinaryWrite(), but it opens the file in the window and doesn't provide it for download. At least this isnt silent though.

EDIT I suspect something I'm using is silencing the result. I'm going to start looking into plugins and things I've added.

I tried several permutations of the answers below, but nothing worked across both browsers I have available. HttpContext.Response.AddHeader("Content-Disposition", "attachent;filename =" + fileLocInfo.FileName ); return File(stream.ToArray(), "application/force-download" , fileLocInfo.FileName ); Result - fails in firefox "Corrupted Content Error"

HttpContext.Response.ContentType = "application/octet-stream";
HttpContext.Response.AddHeader("Content-Disposition", "attachent;filename =" + fileLocInfo.FileName );
return File(stream.ToArray(), "application/force-download" , fileLocInfo.FileName );

Result - shows file in browswer in ie. (not for download), firefox = "Corrupted Content Error"

HttpContext.Response.ContentType = "application/force-download"; ////"application/octet-stream";
HttpContext.Response.AddHeader("Content-Disposition", "attachent;filename =" + fileLocInfo.FileName );
return File(stream.ToArray(), fp.MimeType , fileLocInfo.FileName );

Result - shows file in browswer in ie. (not for download), firefox = "Corrupted Content Error"

public FileContentResult FileDownload(string id)
return File(stream.ToArray(), fp.MimeType , fileLocInfo.FileName );

Result - silent in ie. (no show), provided for download in firefox

public FileStreamResult FileDownload(string id)
return File(stream, fp.MimeType , fileLocInfo.FileName );

Result - silent in i.e.

other thoughts: I can get both to show in the browser, (although not for download) if I binarywrite from the Repsonse Object. Its quite annoying.

Thanks for your answers, but I think this problem may be specific to my solution.

monkeyhouse
  • 2,875
  • 3
  • 27
  • 42
  • also, although this file is static content pulled from the disk, I need to send another file that is dynamiclly generated into a memory stream (in another controller). Real issue. – monkeyhouse Jun 14 '13 at 20:05
  • 1
    whoa buddy, this is a site for professionals hopefully. Please refrain from calling people names. – Daniel Moses Jun 14 '13 at 20:08
  • I wonder what kind of help you expect from people you are calling *jerkoffs*. Personally if I called someone *a jerkoffs* I would expect to get myself into a fight rather than asking this person some help. But anyways, it's probably your way of seeing things. Good luck by the way with this question. – Darin Dimitrov Jun 14 '13 at 20:09
  • @JoshNoe, you saw a question here? – Darin Dimitrov Jun 14 '13 at 20:11
  • @DarinDimitrov I don't see any explicit questions, but the question is pretty obvious: "why doesn't this display a download indication in IE9?" Seems a little nit-picky to me, just my opinion. – Josh Noe Jun 14 '13 at 20:15

2 Answers2

3

You need to set the HTTP header, so that it knows this should be saved and not just displayed in the browser.

Content-Type: application/octet-stream
Content-Disposition:  attachment; filename=DefaultFileNameHere.txt

Since you are using an ActionResult with a File response you can just change the method signiture and it will automatically add the disposition for you:

public FileContentResult  FileDownload(String id) {....}
Daniel Moses
  • 5,872
  • 26
  • 39
1

Try setting the Content Type to application/force-download.

return File(filePath, "application/force-download", fileName);

This question is a possible duplicate of What content type to force download of text response?, which talks about the method @DMoses mentioned.

Community
  • 1
  • 1
neontapir
  • 4,698
  • 3
  • 37
  • 52
  • +1 This method works fine if you have a static file, but if you are proxying another stream for which you don't know the length, this won't work as I believe the `forced-download` requires a `content-length`, but I could be wrong. – Daniel Moses Jun 14 '13 at 20:18
  • That's a good point. He used `GetFileContentFromDisk`, so I wasn't sure if it was static or not. – neontapir Jun 14 '13 at 20:21