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 I run this code, I foresee to find a Documents Save Dialog in the web internet browser, nonetheless absolutely nothing at all takes area. There may not be any sort of blunders on the C# or JavaScript side. Can any person inform me specifically what i might be carrying out incorrect?

Exactly what I am actually attempting to carry out is supplying the consumers the capacity to export the network details to a stick out report as well as install it, with the help of a documents spare discussion.

After that you can deserialize the json strand in the controller as well as your Open/Save discussion require to appear after striking your hyperlink.

Generally when you point out a filename to the Data approach it automatically adjoins a Content-Disposition header so that the Save-As discussion regularly reveals. I am actually a little bit stunned when you state that your code doesn’t operate. You may also intend to by palm collection this header:.

I’ve tried that also, does not operate. The style “application/vdn. ms-excel” is actually for.xls reports, as well as the one that I’m utilizing is actually for.xlsx documents. I am actually beginning to assume that the code itself is actually necessary, as well as the problem is actually one thing else entirely.

bit late however I was actually possessing a similar issue. To fix it I took advantage of JSON.stringify( columnValues) on the client to enhance my details in to a json cord prior to sending it to the operator.

Leave a Reply

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