MVC3 return A file action causes an intermittent Excel program error

I have a problem that is closely related to this problem . Microsoft Excel Error: "There was a problem sending the command to the program." whereby opening Excel gives an There was an error sending a command to the programerror.

However, instead of the existing and open or shortened file, I use MVC3 with an action that generates a bunch of data, generates an excel file (using NPOI ), writes it to a MemoryStream, and then puts it into the browser using the built-in return File(etc)ActionResult, with something similar (but abbreviated here to facilitate readability):

return File(myMemoryStream, "application/vnd.ms-excel", "filename.xls");

The first time you click on a link that launches this action and returns this file, an error occurs. if you click ok and try again, it will work and will continue to work ... forever

Now I know that this could potentially be related to disabling DDE / plugins or something in Excel - but since I create an Excel workbook and upload it to the memory stream, and not open what exists permanently in the file system, I'm not sure what parameters do I need to delete.

Any suggestions on how to get around this? Maybe I have the wrong mime type?

+3
source share
1 answer

Content-Type/vnd.ms-excel . . /x -msexcel.

Excel ( Excel).

return File(myMemoryStream, "application/vnd.ms-excel", "filename.xls")

return File(myMemoryStream, "application/x-ms-excel", "filename.xls")
+1

All Articles