打赏

mvc actionresult返回各种文件

public ActionResult ReviewFile(string folderName, string fileBasename, string extendName)
{
//以后根据后缀名返回相应的文件
var fileFullName = "~/" + folderName + "/" + fileBasename + extendName;
var path = Server.MapPath(fileFullName);
switch (extendName)
{
case ".html":
return File(path, "text/html");
break;
case ".txt":
return File(path, "text/plain");
break;
case ".doc":
return File(path, "application/msword");
break;
case ".xls":
var downLoadFileName = fileBasename + ".xls";
return File(path, "application/ms-excel", downLoadFileName);
//return File(path, "application/x-excel");
break;
case ".pff":
return File(path, "application/ms-powerpoint");
break;
case ".pdf":
return File(path, "application/pdf");
break;
case ".zip":
return File(path, "application/zip");
break;
default:
var noPointExtentName = extendName.Substring(extendName.IndexOf('.') + 1);
return File(path, "image/" + noPointExtentName);
}
}

posted @ 2016-10-08 16:46  KiteRunner1988  阅读(301)  评论(0编辑  收藏  举报