我有一个文件下载的问题,下载正在用下划线替换所有的空格.
基本上我在这里遇到一个问题:
Response.AddHeader("Content-Disposition","attachment; filename=" + someFileName);
问题是如果someFileName中有一个空格,例如“check this out.txt”,那么用户会被提示下载“check_this_out.txt”.
我认为最好的选择是UrlEncode文件名,所以我试过
HttpUtility.UrlEncode(someFileName);
但它正在用加号替代空格,这使我失望了.所以我刚才试过
HttpUtility.UrlEncode(HttpUtility.UrlDecode("%20"))
并且解码工作正常并给我一个空间,但是编码占用空间,然后再次给我加号.
我在这里缺少什么,这是正确的吗?如果是这样,我应该如何正确地将空格编码成’s’,这就是我所需要的.
解决方法
报价从
this link
I’ve come across this myself. If you
are able to change the spaces to %20s
then IE7 will convert them correctly.
Firefox though will take them
literally ( at least when using the
Content-disposition header) so you
will need to do this for requests from
IE7 only.We did the following in our app. ( a
tomcat based document repository)06000