gpt4 book ai didi

internet-explorer - Internet Explorer 中带有空格的内容处理附件文件名

转载 作者:行者123 更新时间:2023-12-05 01:26:32 29 4
gpt4 key购买 nike

string filename = Server.UrlPathEncode(Path.GetFileName(_Filename)));
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + encodeURIComponent(filename) + "\"");

我写了这样的代码..

它在所有浏览器中都运行良好,但在 Internet Explorer 中,当我单击“另存为”时它运行良好,但当单击“打开”时,我在文件名中得到 %20..

谁能告诉我如何解决这个问题

假设文件名为“New text Document.txt”。下载后打开文件时,我希望它具有相同的名称。我不想将其视为“New_text_Document.txt”。

有办法吗?

它在其他浏览器中对我来说工作正常。我在 Internet Explorer 中只有这个问题。如果我默认不编码,我将获得文件名为“New_text_Document.txt”的文件。

最佳答案

如果您的文件名包含空格,它们将被 URL 编码。编码的空格字符实际上是%20,我们可以在文件名中看到。

为避免这种情况,您可以简单地将空格替换为另一个字符,例如 _

Response.AddHeader("Content-Disposition", "attachment; filename=\"" + 
encodeURIComponent(filename.Replace(" ", "_")) +
"\"");

关于internet-explorer - Internet Explorer 中带有空格的内容处理附件文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11152861/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com