ASP.NET c#文件的下载
2021-04-26 03:26
标签:enc stream cat 文件 pos 保存 文件的 c# system //WriteFile实现下载 string fileName="aaa.zip";//客户端保存的文件名 FileInfo fileInfo=new FileInfo(filePath); ASP.NET c#文件的下载 标签:enc stream cat 文件 pos 保存 文件的 c# system 原文地址:http://www.cnblogs.com/ZXiaoHu-html/p/7904176.html
protected void Button2_Click(object sender, EventArgs e)
{
string filePath=Server.MapPath("DownLoad/aaa.zip");//路径
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.ContentType="application/octet-stream";
Response.ContentEncoding=System.Text.Encoding.GetEncoding("gb2312");
Response.WriteFile(fileInfo.FullName);
Response.Flush();
Response.End();
}