response.write - HttpResponse 用下划线代替文件名中的空格

标签 response.write

下载带有 Response.Write 文件名中的空格的文件时,将用下划线替换,并且当关联的应用程序打开时,会附加方括号中的数字:

Response.AppendHeader("Content-disposition", "attachment; filename=this is the file.xml");
Response.Write(dr["InfopathDoc"]);

这会在关联的应用程序中生成此文件名:

_is _the _文件[1].xml

我怎样才能摆脱下划线,为什么我得到 [1] ?

谢谢

最佳答案

在这里找到了这个问题的解决方案

http://dotnetslackers.com/Community/blogs/kaushalparik/archive/2009/05/06/file-download-problem-filename-with-spaces-truncated-in-ff-and-replaced-by-underscore-in-ie.aspx

要解决 FF 的问题,请在文件名周围添加引号作为

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



对于 IE,请用 '%20' 替换空格

filename = toDownload.Name.Replace(" ", "%20");

关于response.write - HttpResponse 用下划线代替文件名中的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/625503/

相关文章:

c# - 使用响应对象创建子页面弹出窗口会破坏父页面的格式

c# - 如何使 Response.Write 显示特殊字符,如 "<",">"

asp.net - Response.Write() 和 Response.Output.Write() 有什么区别?

javascript - node.js 中的 response.end 连接丢失

asp.net - 此 ASP.NET 功能的文档在哪里? <%= 字符串格式,params object[] args %>

c# - 如何在 ASP.NET c# 中执行多个 ClientScript.RegisterStartupScript?

c# - 写入响应的 XML 文件包含页面 HTML

c# - 在 ASP.NET 中使用 Response.write 生成文件时使用 updateprogress

c# - 为什么 Response.Write 行为在给定场景中会有所不同?

.net - 你如何在 .NET 中提供 JSON 响应数据?