8

We have a .Net Web application where the user can download files. The file name the files can have may contain danish characters æ, ø and å and maybe some other characters of some foreigh language.

We use the class HttpResponseMessage to send the file where ContentDispositionHeaderValue is initialized as an "attachment".

However assigning the

FileName 

property does not work in IE for the Danish characters but works if I assign the file name to

FileNameStar

where the filename gets automatically encoded to the right format.

So this works:

Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
    FileNameStar = "filename with æ ø and å"
};

I can however not find any documentation as to why it is automatically encoded, and which browsers support this feature.

Searching the internet, gives suggestions that I should url encode the string before assigning it to FileNamestar property. But this is not necessary, as I can see in the http trace that it is encoded correctly.

Do all major browsers support this? And can I be sure that the filenames are encoded correctly?

Thanks Jihad

Jihad Haddad
  • 592
  • 1
  • 6
  • 19

1 Answers1

6

Taken from here:

The FileNameStar property uses IETF RFC 5987 encoding. The FileName and FileNameStar properties differ only in that FileNameStar uses the encoding defined in IETF RFC 5987, allowing the use of characters not present in the ISO-8859-1 character set.

Jonas
  • 4,683
  • 4
  • 45
  • 81
  • 1
    Thanks. But which browsers support this, and can I send both FileName and FileNameStar in the same request? – Jihad Haddad Feb 14 '17 at 14:08
  • Most browsers support this. If your file name is ISO-8859-1 character set then use FileName if it contains UTF characters use use FileNameStar. If can be both use FileNameStar it will work in both cases. – Jonas Feb 28 '17 at 07:35