111,120
社区成员
发帖
与我相关
我的任务
分享string filePath = "D:\\down\\" + linkButton.Text;// 假设linkButton.Text就是文件名
// 文件不存在,退出
if (!System.IO.File.Exists(filePath))
return;
Response.Clear();
Response.Charset = "gb-2312";
Response.Buffer = true;
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
string downloadFilename = System.IO.Path.GetFileName(filePath);
Response.AppendHeader("Content-Disposition", "attachment;filename=" + downloadFilename);
Response.ContentType = "application/unknown";
// 直接把文件写入Http响应输出流
Response.WriteFile(filePath);
Response.Flush();
Response.Close();
Response.End();