I use the following code to send files from my server to the client:
Response.AppendHeader("content-disposition", "attachment; filename=" + FileName);
Response.ContentType = MimeType;
Response.WriteFile(PathToFile);
Response.End();
This works fine. Problem is, that when I download files from Internet Explorer, special characters, like the danish æ, ø and å, gets interpreted wrong. So i file with the name ‘Test æ ø å file.txt’ downloads as ‘Test æ_ø_Ã¥ file.txt’
I´ve tried adding Byte Order Mark to the response:
byte[] BOM = { 0xEF, 0xBB, 0xBF };
Response.BinaryWrite(BOM);
And setting the charset:
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
But none if it helped.
This seems only to be a problem in Internet Explorer.
The headers doesn’t use the encoding of the content, so it won’t help to change the content encoding. There is a standard for specifying encoding for the header parameters, but it’s pretty new, so it won’t be fully supportred in all browsers:
http://greenbytes.de/tech/webdav/rfc5987.html
This is how you would encode the name:
The text ending up in the header would look like this:
Note: The code encodes all characters except alphanumeric. That works, but not all other characters need encoding. You could evolve the code to leave a few more characters unencoded, after checking the standards.