|
-
July 17th, 2009, 11:50 AM
#1
IE and international characters
Hello,
I am writing an application where the user needs to be able to download a file.
So I have the following code which does the downloading:
Code:
public ActionResult GetFile(byte[] value, string fileName)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.ContentType = "application/msword";
Response.Charset = "utf-8";
Response.HeaderEncoding = UnicodeEncoding.UTF8;
Response.ContentEncoding = UnicodeEncoding.UTF8;
Response.TrySkipIisCustomErrors = true;
Response.BinaryWrite(value);
Response.End();
return null;
}
The code above is kind of old school and does not use the MVC's File() method and that is because as it turns out the framework does not support international characters at all so any filename which contains an International character was throwing an exception. ALso many things are hard coded because I am in the proof-of-concept stage right now and want to get it working on a general level fist. The problem I am having is that in IE when the download dialog comes up the international characters in the file name which shows in the dialog are messed up. I tested it in FF and Chrome and everything looks fine.
In IE( I am using IE 7) I did the following so far:
1) Tools - Internet Options - Languages and Added the Swedish Language and moved it to the
top.
2) Under Tools - Internet Options - Advanced - International I selected all of the check boxes.
I am testing using the localhost in VS 2008
What am I missing?
THanks
Susan
-
July 17th, 2009, 01:14 PM
#2
Re: IE and international characters
I found a solution and thought I will post it here:
public ActionResult GetFile(byte[] value, string fileName)
{
string fileExtension = Path.GetExtension(fileName);
string contentType = GetContentType(fileExtension);
Response.Clear();
if (Request.Browser.Browser == "IE")//IE needs special handling in order to display the international
//characters in the file name
{
string attachment = String.Format("attachment; filename={0}", Server.UrlPathEncode(fileName));
Response.AddHeader("Content-Disposition", attachment);
}
else
Response.AddHeader("Content-Disposition", "attachment; filename="+fileName);
Response.ContentType = contentType;
Response.Charset = "utf-8";
Response.HeaderEncoding = UnicodeEncoding.UTF8;
Response.ContentEncoding = UnicodeEncoding.UTF8;
Response.BinaryWrite(value);
Response.End();
return null;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|