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";
//设定响应类型为下载
this.Response.ContentType = "application/x-zip-compressed";
//获取下载文件在服务器端的物理路径
string downLoadPath = this.Server.MapPath("Download\\DownDemo.txt");
//添加响应头标示信息 this.Server.UrlPathEncode对下载文件名进行编码 防止文件名乱码
this.Response.AddHeader("Content-Disposition",string.Format("attachment;filename={0}",this.Server.UrlPathEncode(downLoadFileName)));
//下载文件输出
/*
TransmitFile方法可以保证400M以上的文件正确下载
* 所以笔者推荐使用 TransmitFile方法
*/
this.Response.TransmitFile(downLoadPath);
}
}