I'm currently trying to implement a controller where you can download files from (more specifically jar-archives). The files are stored on disk and not in database. So far I have come up with this:
public FilePathResult GetFile(String fileName)
{
return File(Path.Combine(Server.MapPath("~/App_Data/Bundles"), fileName), "application/java-archive");
}
Nevermind the lack of error handling and such at this time. The file do get downloaded this way, however it gets the wrong name. Instead of, for example, "sample.jar" the file gets the controller's name, "GetFile", (without extension).
Any ideas on what I am doing wrong?
Use the overload which allows you to specify the fileDownloadName
.
return File(Path.Combine(Server.MapPath("~/App_Data/Bundles"), fileName),
"application/java-archive",
fileName);
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