我正在将文件从 ASP.NET Page 发送到浏览器。为了正确发送文件名,我添加了一个标题:
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
问题是当文件包含空格(例如“abc def”)时,浏览器只收到文件名的“abc”部分。我试过: Server.HtmlEncode 但它没有帮助。
你知道如何解决这个问题吗?
PK
最佳答案
将文件名放在引号中:-
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
关于发送文件时的 ASP.NET 文件名编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1588325/