首页 > Web开发 > 详细

asp.net已流的方式下载文件

时间:2016-10-27 13:05:47      阅读:251      评论:0      收藏:0      [点我收藏+]

string filePath = context.Server.MapPath("~/" + uploadFolder+"/"+file_name);//路径
System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
if (fileInfo.Exists == true)
{
//以字符流的形式下载文件
FileStream fs = new FileStream(filePath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
//通知浏览器下载文件而不是打开
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(file_name, System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
else
{
//context.Response.Write("the download files is not exists");
}

asp.net已流的方式下载文件

原文:http://www.cnblogs.com/huguole/p/6003182.html

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