ASP.NET 后台下载文件方法
生活随笔
收集整理的這篇文章主要介紹了
ASP.NET 后台下载文件方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 void DownLoadFile(string fileName)
2 {
3 string filePath = Server.MapPath(fileName);//路徑
4
5 //以字符流的形式下載文件
6 FileStream fs = new FileStream(filePath, FileMode.Open);
7 byte[] bytes = new byte[(int)fs.Length];
8 fs.Read(bytes, 0, bytes.Length);
9 fs.Close();
10 Response.ContentType = "application/octet-stream";
11 //通知瀏覽器下載文件而不是打開
12 Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
13 Response.BinaryWrite(bytes);
14 Response.Flush();
15 Response.End();
16 }
?
轉載于:https://www.cnblogs.com/Chaser-Eagle/p/3684589.html
總結
以上是生活随笔為你收集整理的ASP.NET 后台下载文件方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 安装setuptools的Unicode
- 下一篇: shiro 散列加盐(salt) 次数的