码迷,mamicode.com
首页 > Web开发 > 详细

mvc actionresult返回各种文件

时间:2016-10-08 18:55:41      阅读:323      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!