Return to site

Asp Net Mvc Download File

broken image


  1. Asp Net Mvc Download File For Windows 7
  2. Asp.net Mvc Download File Csv
  3. Asp.net Mvc Download File Link
  4. Download File Using Angularjs And Asp Net Mvc
  5. Asp.net Mvc Download File Button

I've had it suggested to me that I should use FileResult to allow users to download files from my Asp.Net MVC application. But the only examples of this I can find always has to do with image files (specifying content type image/jpeg).

But what if I can't know the file type? I want users to be able to download pretty much any file from the filearea of my site.

I had read one method of doing this (see a previous post for the code), that actually works fine, except for one thing: the name of the file that comes up in the Save As dialog is concatenated from the file path with underscores (folder_folder_file.ext). Also, it seems people think I should return a FileResult instead of using this custom class that I had found BinaryContentResult.

Creates a FilePathResult object by using the file name, the content type, and the file download name. Protected internal virtual System.Web.Mvc.FilePathResult File (string fileName, string contentType, string fileDownloadName). Fortunately, it's easy to write code to upload and download files using ASP.NET MVC. To start, we need a view and controller pair to upload a file. This is the same HTML and MVC code that you already know. https://tsaknegittheo1985.mystrikingly.com/blog/download-game-strip-poker-pc.

Anyone know the 'correct' way of doing such a download in MVC?

EDIT:I got the answer (below), but just thought I should post the full working code if someone else is interested:

Community
AndersAnders

7 Answers

You can just specify the generic octet-stream MIME type:

Official Site. Explore a wild post-apocalyptic world in the stand-alone sequel to Far Cry 5. Available now on PS4, Xbox One, PC. https://tsaknegittheo1985.mystrikingly.com/blog/far-cry-5-download-game.

Ian HenryIan Henry

The MVC framework supports this natively. The System.Web.MVC.Controller.File controller provides methods to return a file by name/stream/array.

For example using a virtual path to the file you could do the following.

JonathanJonathan

If you're using .NET Framework 4.5 then you use use the MimeMapping.GetMimeMapping(string FileName) to get the MIME-Type for your file. This is how I've used it in my action.

user1023602
Salman Hasrat KhanSalman Hasrat Khan

Phil Haack has a nice article where he created a Custome File Download Action Result class. You only need to specify the virtual path of the file and the name to be saved as.

I used it once and here's my code.

In my example i was storing the physical path of the files so i used this helper method -that i found somewhere i can't remember- to convert it to a virtual path

Here's the full class as taken from Phill Haack's article

Manaf Abu.RousManaf Abu.Rous

Thanks to Ian Henry!

For the control of documented information, does your organization address the distribution, access, retrieval and use? Iso 9001 2015 pdf download.

In case if you need to get file from MS SQL Server here is the solution.

Asp Net Mvc Download File For Windows 7

Where AppModel is EntityFramework model and MyFiles presents table in your database.FileData is varbinary(MAX) in MyFiles table.

DeveloperDeveloper

its simple just give your physical path in directoryPath with file name

DARSHAN SHINDEDARSHAN SHINDE

Asp.net Mvc Download File Csv

GetFile should be closing the file (or opening it within a using). Then you can delete the file after conversion to bytes-- the download will be done on that byte buffer.

Asp.net Mvc Download File Link

So in your download method..

CDichterCDichter

Download File Using Angularjs And Asp Net Mvc

Download

Asp.net Mvc Download File Button

Not the answer you're looking for? Browse other questions tagged c#asp.net-mvc-2 or ask your own question.





broken image