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 );
}
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.