Asp.net大文件下载
public partial class _Default : System.Web.UI.Page
{
??? protected void Page_Load(object sender, EventArgs e)
??? {
??? }
??? protected void Button1_Click(object sender, EventArgs e)
??? {
??????? //用戶下載文件時保存文件使用的默認命名
??????? string downLoadFileName = "DownDemo.txt";
??????? //設(shè)定響應(yīng)類型為下載
??????? this.Response.ContentType = "application/x-zip-compressed";
??????? //獲取下載文件在服務(wù)器端的物理路徑
??????? string downLoadPath = this.Server.MapPath("Download\\DownDemo.txt");
??????? //添加響應(yīng)頭標示信息? this.Server.UrlPathEncode對下載文件名進行編碼 防止文件名亂碼
??????? this.Response.AddHeader("Content-Disposition",string.Format("attachment;filename={0}",this.Server.UrlPathEncode(downLoadFileName)));
??????? //下載文件輸出
??????? /*
??????????? TransmitFile方法可以保證400M以上的文件正確下載
???????? * 所以筆者推薦使用 TransmitFile方法
???????? */
??????? this.Response.TransmitFile(downLoadPath);
??? }
}
總結(jié)
以上是生活随笔為你收集整理的Asp.net大文件下载的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 刀与枪的碰撞zhajinhua2012
- 下一篇: 战斧湖战役之后的5rnm