I had a similar problem. You must use HttpUtility.UrlEncode or Server.UrlEncode to encode the file name. I also remember that firefox did not need this. He also destroyed the file name when it is encoded in url. My code is:
// IE needs url encoding, FF doesn't support it, Google Chrome doesn't care if (Request.Browser.IsBrowser ("IE")) { fileName = Server.UrlEncode(fileName); } Response.Clear (); Response.AddHeader ("content-disposition", String.Format ("attachment;filename=\"{0}\"", fileName)); Response.AddHeader ("Content-Length", data.Length.ToString (CultureInfo.InvariantCulture)); Response.ContentType = mimeType; Response.BinaryWrite(data);
Edit
I read the specification more carefully. First of all, RFC2183 states that:
The current [RFC 2045] grammar restricts parameter values (and therefore Content-Disposition file names) to US-ASCII.
But then I found links that [RFC 2045] is deprecated, and I need to reference RFC 2231 , which says:
Asterisks ("*") are reused to provide an indicator that language and character set information is present and encoding is being used. One quote ("'") is used to distinguish between the character set and language information at the beginning of the cost parameter. Percentage signs ("%") are used as the encoding flag, which is consistent with RFC 2047.
This means that you can use UrlEncode for non-ascii characters, as I said earlier, but you can also add a description of the encoding. Here is an example:
string.Format("attachment; filename*=UTF-8''{0}", Server.UrlEncode(fileName));
I didn’t try, though ..
Sergej Andrejev
source share