按钮事件实现下载:
private void ResponseFile(string path)
{
System.IO.FileInfo fi = new System.IO.FileInfo(path);
Response.Clear();
Response.ClearHeaders();
Response.Buffer=false;

Response.AppendHeader("Content-Disposition", "attachment;filename=" +

System.Web.HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(path)));
Response.AppendHeader("Content-Length", fi.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(path);
Response.Flush();
Response.End();
}
path:设置您需要让别人下载的文件路径和文件名,任何格式的文件都可以,路径最好用虚拟路径。
private void ResponseFile(string path)
{
System.IO.FileInfo fi = new System.IO.FileInfo(path);
Response.Clear();
Response.ClearHeaders();
Response.Buffer=false;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + 
System.Web.HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(path)));
Response.AppendHeader("Content-Length", fi.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(path);
Response.Flush();
Response.End();
}

浙公网安备 33010602011771号