protected void Page_Load(object sender, EventArgs e)
{
string downLoadPath = @"D:\4Deploy\1.docx";
Response.Clear();
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "1.docx"));
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.TransmitFile(downLoadPath);
HttpContext.Current.Response.End();
}核心代码就上面了, 我是从一个页面window.open("downLoad.aspx"); 调试环境下可以下载,到了测试环境下的时候就无法下载了,页面一闪没了,没有进行下载。代码是从老项目中100%copy过来的,现在把网上的办法都试过了。没效果
{
string downLoadPath = @"D:\4Deploy\1.docx";
Response.Clear();
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "1.docx"));
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.TransmitFile(downLoadPath);
HttpContext.Current.Response.End();
}核心代码就上面了, 我是从一个页面window.open("downLoad.aspx"); 调试环境下可以下载,到了测试环境下的时候就无法下载了,页面一闪没了,没有进行下载。代码是从老项目中100%copy过来的,现在把网上的办法都试过了。没效果
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string fileName = "XXX.docx";//客户端保存的文件名
string filePath = Server.MapPath("test.docx");//路径 FileInfo fileInfo = new FileInfo(filePath);
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();
}
}
string fileName = "XXX.ZIP";//客户端保存的文件名
string filePath = Server.MapPath("test.ZIP");//路径