如何在asp.net mvc中使用FileResult下载文件。我在下面尝试此代码,但显示错误:
找不到路径'E:\ SRUTHI \ LMS \ LMS \ TrainingMaterial \ Uploads \ Task List.xlsx'的一部分。
[HttpGet]
public FileResult FileDownload(string filename)
{
if (filename != "")
{
string[] Filess = filename.Split('/');
string file = Server.MapPath(filename);
//string contentType = "application/image";
string fileName = Filess[Filess.Count() - 1];
string contentType = MimeMapping.GetMimeMapping(fileName);
return File(file, contentType, fileName);
}
return null;
}