下面是我的代码:
Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename=file.xlsx");
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.BinaryWrite(pck.GetAsByteArray());
Response.End();问题是,当运行此代码(单击按钮)时,我不会在浏览器中下载文件(在Chrome \IE中尝试)。
pck是一个excel文件(用副加库生成)。我甚至不知道如何调试这部分代码。它什么都没做。
下面是我在浏览器中遇到的错误:
Sys.WebForms.PageRequestManagerParserErrorException: Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器接收到的消息。导致此错误的常见原因是,当响应被Response.Write()调用修改时,响应筛选器、HttpModules或服务器跟踪被启用。 详细信息:在PKX��@ϖ�附近解析错误。
发布于 2012-04-12 01:33:18
我相信你在使用更新面板。执行异步回发时不能下载文件。添加按钮,它将下载文件作为更新面板的回发触发器。
发布于 2012-04-12 01:30:21
你走在正确的轨道上。我觉得你漏了几句台词:
Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename=file.xlsx");
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.BinaryWrite(pck.GetAsByteArray());
Response.Flush();
Response.Close();
Response.End();https://stackoverflow.com/questions/10115979
复制相似问题