//提供下载的文件,不编码的话文件名会乱码
private string fileName = HttpContext.Current.Server.UrlEncode("规范.rar");
private string filePath = HttpContext.Current.Server.MapPath("规范.rar");
//使用TransmifFile下载文件
protected void btnDL1_Click(object sender, EventArgs e)
{
FileInfo info = new FileInfo(filePath);
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename="+ fileName);
//不指明Content-Length用Flush的话不会显示下载进度
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(filePath, 0, fileSize);
Response.Flush();
Response.Close();
}
转载于:https://www.cnblogs.com/yxlblogs/archive/2013/04/25/3043525.html