【问题标题】:Download csv file works in IE8 but not in IE10下载 csv 文件在 IE8 中有效,但在 IE10 中无效
【发布时间】:2014-08-25 17:45:43
【问题描述】:

我们公司最近从IE8“升级”到了IE10。允许用户下载文件的网页停止正常运行。现在,IE10 只是挂起,因为用户等待他的文件。这些页面仍可在最新版本的 Chrome 中运行。

我查看了How do I get csv file to download on IE? Works on firefox 11 并尝试修改我的代码,但无济于事。

还有一点信息:停止工作的页面在按钮单击事件中有以下代码。当代码在页面加载事件中时,即使在 IE10 中,完全相同的代码(尽管文件名不同)仍然有效。

FileInfo file = new FileInfo(@"C:\Reports\" + OutputFileName); // "report.csv"
Context.Response.Clear();
Context.Response.ClearHeaders();
Context.Response.ClearContent();
Context.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Context.Response.AddHeader("Content-Length", file.Length.ToString());
Context.Response.ContentType = "text/csv";
Context.Response.Flush();
Context.Response.TransmitFile(file.FullName);
Context.Response.End();

非常感谢您的帮助。

【问题讨论】:

  • 你确定服务器端代码执行了吗?
  • 是的,服务器端代码执行了——我看到DB表已经更新了。

标签: csv download internet-explorer-10


【解决方案1】:

此代码有效。在传输之后进行刷新就可以了。

FileInfo file = new FileInfo(@"C:\Reports\" + OutputFileName); // "report.csv"
Context.Response.Clear();
Context.Response.ClearHeaders();
Context.Response.ClearContent();
Context.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Context.Response.AddHeader("Content-Length", file.Length.ToString());
Context.Response.ContentType = "text/csv";
Context.Response.TransmitFile(file.FullName);
Context.Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();

【讨论】:

    猜你喜欢
    • 2014-12-16
    • 1970-01-01
    • 1970-01-01
    • 2012-05-19
    • 2023-03-13
    • 2021-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多