Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.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
IE在文件打开时将[1]添加到文件名asp.net(c#)_Asp.net_Internet Explorer - Fatal编程技术网

IE在文件打开时将[1]添加到文件名asp.net(c#)

IE在文件打开时将[1]添加到文件名asp.net(c#),asp.net,internet-explorer,Asp.net,Internet Explorer,我正在发送一个带有http响应的excel文件,当单击“打开”时,IE会在文件名的末尾添加一个[1]。在“保存”文件时,它不会。有办法解决吗 HttpResponse response = HttpContext.Current.Response; response.Clear(); response.AddHeader("content-disposition", "attachment;filename=" + filename+".xlsx"); response

我正在发送一个带有http响应的excel文件,当单击“打开”时,IE会在文件名的末尾添加一个[1]。在“保存”文件时,它不会。有办法解决吗

HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.AddHeader("content-disposition", "attachment;filename=" + filename+".xlsx");             
response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";  
response.ContentEncoding = System.Text.Encoding.Unicode;
response.BinaryWrite(pkg.GetAsByteArray()); //pkg is ExcelPackage 
response.End();

这很可能是因为您已经打开了一次文件(或者可能打开了另一个同名文件),所以它保存了一份文件副本以供查看。
[1]
只是为了避免在internet临时文件文件夹中出现命名冲突


这完全是在客户端完成的,因此我怀疑在服务器端代码中是否有任何方法可以做到这一点。

我认为问题在于,当您单击“打开”时,文件必须保存到临时文件夹中,但具有相同名称的文件已经存在,因此它会添加“[1]”以使其唯一。David,你说的是internet临时文件文件夹吗?没有具有此名称的文件。我尝试过给一个随机的“JSFLJASLDFLSKJ”文件名,它也做了同样的事情。文件名中有点吗?检查这里的第二个答案:谢谢,不。文件名不包含点,除了扩展名前面的点。没有这样的文件名。文件名是根据日期生成的。无论您打开同一文件多少次,它都会添加[1],而不会像保存文件时那样递增。