//TransmitFile实现下载
protected void Button1_Click(object sender, EventArgs e)
{
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=8月份报表.zip");
string filename = Server.MapPath("DownLoad/8月份报表.zip");
//指定编码 防止中文文件名乱码
Response.HeaderEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.TransmitFile(filename);
}
//WriteFile实现下载
protected void Button2_Click(object sender, EventArgs e)
{
string fileName = "asd.txt";//客户端保存的文件名
string filePath = Server.MapPath("DownLoad/aaa.txt");//路径
FileInfo fileInfo = new FileInfo(filePath);
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition",
C# asp.net中四种文件下载方法
最新推荐文章于 2024-07-04 16:19:48 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)