首页 > Web开发 > 详细

mvc actionresult返回各种文件

时间:2016-10-08 18:52:31      阅读:281      评论:0      收藏:0      [点我收藏+]

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);
}
}

mvc actionresult返回各种文件

原文:http://www.cnblogs.com/taoshengyujiu/p/5939291.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!