c# Asp.NET MVC downloading excel file using FileStreamResult

I need to develop a method, that will receive model, build stand out from it (structure and getting part is done without issues) and after that export (let user download it) using memory stream (without saving it on the server). I am new to ASP.NET and MVC so i discovered guide and developed this as a tutorial project:

Now i have to change this code to make this method sent my excel file without conserving my excel file on server. I have tried to google some guides and answers here, on stack, however for now i cant find a service, which i can execute.

I think i must utilize FileStreamResult, however all guides provide no particular info about developing and placing my file into stream. c# Asp.NET MVC downloading excel file using FileStreamResult http://www.iditect.com/faq/excel/asp-net-mvc-download-excel-file.html

It does not appear that the Microsoft.Office.Interop.Excel.Workbook interface (msdn) will permit you to transform your workbook to a memory stream.

However, in the past I have used an external library, EPPlus, which has actually worked exceptionally.

See listed below for code using EPPlus which will not require you to save the file on the server.

I’m downloading an excel file within C# action method the reutrns a FileResult, like this:

return File( bindata, “application/octet-stream”, “mytestfile.xls”);.

When I by hand navigate to the URL that refers the above approach, then I get the rendered out representation of the file. The file will not download with a Save As -dialog.

Exists a method to require the download to happen through Conserve As -dialog?

I have a feeling you are getting this habits because of the media type you are returning.

Attempt altering the media type to application/vnd. ms-excel like this:
return File(bindata, "application/vnd.ms-excel", "mytestfile.xls");

When you specify a filename to the File approach it automatically appends a Content-Disposition header so that the Save-As dialog constantly reveals, typically. So I am a bit stunned when you say that your code doesn’t work. You might also aim to by hand set this header:.

Exactly what I’m attempting to execute is providing the users the ability to export the grid information to a stand out file and download it, with the assistance of a file save dialog.

When I run this code, I anticipate to see a File Save Dialog in the web browser, however absolutely nothing takes place. There aren’t any mistakes on the C# or JavaScript side. Can anyone tell me exactly what i could be doing incorrect?

I’ve tried that too, doesn’t work. The type “application/vdn. ms-excel” is for.xls files, and the one that I’m using is for.xlsx files. I’m beginning to think that the code itself is appropriate, and the issue is something else completely.

bit late but I was having a similar concern. To fix it I utilized JSON.stringify( columnValues) on the client to transform my information into a json string prior to sending it to the controller.

Then you can deserialize the json string in the controller and your Open/Save dialog need to appear after hitting your link.

Leave a Reply

Your email address will not be published. Required fields are marked *