MVC资源下载-创新互联
{

//string filePath = Server.MapPath("File/") + Session["file"].ToString();//要下载的资源在本机
string filePath =@"\192.168.1.90wwwrootimg.cn-school.comimages667027ee9425480e8881fd923158317d.png";//要下载的资源在某个服务器
FileStream fs = new FileStream(filePath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
return new EmptyResult();
}
分享题目:MVC资源下载-创新互联
网站地址:http://scyanting.com/article/ihsjp.html