asp.net导出excel部署后无法下载的问题
做的一个导出excel的功能(先生成excel文件存放到服务器的文件夹下,然后下载到客户端),主要代码如下:stringtemp_path=Server.MapPath(...
做的一个导出excel的功能(先生成excel文件存放到服务器的文件夹下,然后下载到客户端),主要代码如下:
string temp_path = Server.MapPath("../../SysFiles");//生成的文件存放路径
if (!Directory.Exists(temp_path))
{
Directory.CreateDirectory(temp_path);
}
string tick = DateTime.Now.Ticks.ToString();
string save_path = temp_path + "\\" + tick + ".xls";
wsTmp.SaveAs(save_path, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing);
if (save_path != null && File.Exists(save_path))
{
System.IO.FileInfo file = new System.IO.FileInfo(save_path);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", file.Length.ToString());
//Response.ContentType = "application/octet-stream";
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
Response.WriteFile(file.FullName);
Response.End();
}
本机调试没有问题,发布到iis上后就下载不下来,(到SysFiles文件下看可以看到生成的excel文件)
出现"ie无法下载xxx.xls 与服务器的连接被重置....."
iis6.0 windows2003 展开
string temp_path = Server.MapPath("../../SysFiles");//生成的文件存放路径
if (!Directory.Exists(temp_path))
{
Directory.CreateDirectory(temp_path);
}
string tick = DateTime.Now.Ticks.ToString();
string save_path = temp_path + "\\" + tick + ".xls";
wsTmp.SaveAs(save_path, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing);
if (save_path != null && File.Exists(save_path))
{
System.IO.FileInfo file = new System.IO.FileInfo(save_path);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", file.Length.ToString());
//Response.ContentType = "application/octet-stream";
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
Response.WriteFile(file.FullName);
Response.End();
}
本机调试没有问题,发布到iis上后就下载不下来,(到SysFiles文件下看可以看到生成的excel文件)
出现"ie无法下载xxx.xls 与服务器的连接被重置....."
iis6.0 windows2003 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询