Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.NET Response.BinaryWrite在创建Excel文件时在ie中引发错误_Asp.net_Excel - Fatal编程技术网

ASP.NET Response.BinaryWrite在创建Excel文件时在ie中引发错误

ASP.NET Response.BinaryWrite在创建Excel文件时在ie中引发错误,asp.net,excel,Asp.net,Excel,我有一个返回字节数组的方法。然后,我将此数组作为excel文件写入输出流。一些用户报告ie7中的Internet Explorer无法打开此Internet站点错误 当我在使用ie9的测试环境中运行它时,我没有得到这个错误。但是,有时我第一次单击链接时,Excel会打开,但我会收到一个错误,即将命令发送到程序时出现问题,文件无法加载到Excel中。如果我再次单击链接,该文件将在Excel中打开。下面是在用户单击页面上的链接后通过响应流发送字节数组的代码 byte[] buffer = GetBi

我有一个返回字节数组的方法。然后,我将此数组作为excel文件写入输出流。一些用户报告ie7中的Internet Explorer无法打开此Internet站点错误

当我在使用ie9的测试环境中运行它时,我没有得到这个错误。但是,有时我第一次单击链接时,Excel会打开,但我会收到一个错误,即将命令发送到程序时出现问题,文件无法加载到Excel中。如果我再次单击链接,该文件将在Excel中打开。下面是在用户单击页面上的链接后通过响应流发送字节数组的代码

byte[] buffer = GetBinary();
Response.ContentType = "application/vnd.ms-excel";
Response.Buffer = true;
Response.Expires = 0;
Response.AddHeader("Content-Type", "application/vnd.ms-excel");
Response.AddHeader("Content-Length", buffer.Length.ToString());
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.AddHeader("Content-Disposition", "attachment;filename=xx.xls");
Response.BinaryWrite(buffer);
Response.End();

如果有任何不同,他们单击的链接会打开一个新窗口,上面的代码块将在新页面的page_load事件中执行。是什么导致了这些错误?我以前使用过类似的代码,但没有问题。

我想Response.AddHeaderContent-Length、buffer.Length.ToString可能有点奇怪,请删除并重试。谢谢,但我在最初没有问题时添加了这一点。