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

mvc文件下载

时间:2017-11-13 21:23:41      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:map   oct   exce   tostring   res   ica   byte   response   文件名   

public ActionResult xiazai(int id)
{
DataTable dt = bll.chaxun(id);
//获取文件名字
var filename = dt.Rows[0]["SCName"];
//完整路径
var newname = Server.MapPath("/EXCEL/" + filename);
//文件流
FileStream fs=new FileStream(newname.ToString(),FileMode.Open);
//数组
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.Charset = "UTF-8";
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = Encoding.Default;
Response.AddHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(filename.ToString()));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();


return View();
}

mvc文件下载

标签:map   oct   exce   tostring   res   ica   byte   response   文件名   

原文地址:http://www.cnblogs.com/shenghuotaiai/p/7827844.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!