Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I link to downloadable files in ASP.NET MVC?

I am new to ASP.NET MVC and I'am trying to link to downloadable files (.zip, .mp3, .doc, etc).
I have the following view: ProductName which maps to: http://domain/ProductName
I have a .zip file that must map to URL http://domain/ProductName/Product.zip

Questions

Where do I place this .zip file in the MVC folder structure?
How do I add link to this .zip file in MVC? Is there a Url.* method that do this?

like image 564
Gautam Jain Avatar asked Nov 28 '22 23:11

Gautam Jain


1 Answers

You can use FilePathResult or Controller.File method.

protected internal virtual FilePathResult File(string fileName, string contentType, string fileDownloadName) {
  return new FilePathResult(fileName, contentType) { FileDownloadName = fileDownloadName };
}

Sample code action method.

public ActionResult Download(){
  return File(fileName,contentType,downloadFileName);
}

Hope this code.

like image 58
takepara Avatar answered Dec 16 '22 10:12

takepara