So I'm returning a FileContentResult
from an action like this:
return File(pck.GetAsByteArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "MyExcelFile.xlsx");
When clicking "Open" in IE (I'm using IE9, version 9.0.8112.16421), it says "File couldn't be downloaded" and the user is presented with a 'Retry' button. If they click Retry, it works fine. If they click Save, it works fine. In Firefox, it works fine.
How can I allow the user to open the file when the click Open the first time?
I was able to "trick" IE into doing the right thing by modifying the URL. It's kind of hacky, but here's the detail. HTH.
As a good MVC coder, I used Url.Action() to generate the right link in my view to my controller action. The result was "/Subscription/DownloadArchive", and I had the same issue. (I'm streaming a ZIP file down, but it seems no different than your CSV.) On a whim just now, after reading your post, I hard-coded the URL to "/Subscription/DownloadArchive/Archive.zip". I ignore the "Archive.zip" in code, but that is in fact the file name I return from my controller's action.
Presto!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With