下载带有 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/