开发者

ASP.NET Export to Excel, if filename contains character # or /, it is converted into underscore(_) while poping-up the open/save dialog!

string filename = "Category#FileName";

response.AddHeader("content-disposition", "attachment; filenam开发者_开发百科e=" + filename);
response.ContentType = "text/csv";
response.AddHeader("Pragma", "public");

Final file name => Category_FileName

I would appreciate your help here, pls help!


A filename can't contain the character / under Windows (or most other OSes), so you won't be able to stop that one getting converted. # is left alone by most browsers, the odd one out being IE.

Content-Disposition filenames are a bit limited. Non-ASCII characters aren't reliable in them and the proper escaping according to the RFC doesn't work. If you want to get Unicode characters into a default download filename​—or certain other punctuation characters including # in IE—you have to URL-encode it and include that as a trailing part of the path, omitting the Content-Disposition filename. eg:

http://www.example.com/myscript.aspx/foo%23bar.xls

myscript.aspx:

response.AddHeader("Content-Disposition", "attachment");

(You still can't include / in a filename this way as web servers tend to block all URLs with %2F in. In any case, as above, you wouldn't be able to save it with a / in the filename anyway.)


Sadly this is a limitation of IE.

According to Microsoft, the following characters will be converted to underscores if you use them in the file attachment's filename attribute:

<   Left angle bracket
>   Right angle bracket
\   Backslash
"   Quotation mark
/   Slash mark
:   Colon
|   Vertical bar
?   Question mark
*   Asterisk
    Space

See https://support.microsoft.com/en-us/help/949197/certain-characters-in-a-file-name-may-be-converted-to-underscores-when-a-user-downloads-a-file-by-using-windows-internet-explorer-7

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜