Unicode Headers for Filedownload

W

WO70

Hi,

maybe someone had the same problem:
http://support.microsoft.com/kb/895262/en-us

This Hotfix is only available for Windows 2003, but we also use Windows
2000 and for development Windows XP. So I thought ASP.NET 2.0 will make
things better.

And now ASP.NET is there and I found this:
http://msdn2.microsoft.com/en-us/library/system.web.httpresponse.headerencoding.aspx

But if I set the Encoding to Unicode, I get this:
'utf-16' cannot be used as Header Encoding

Here is a little testing app:
string filename = "abcdeäüö.txt";

System.Text.UnicodeEncoding enc = new
System.Text.UnicodeEncoding();

Response.ContentType = "text/plain";
Response.Clear();
byte[] buffer ={ 65 };
Response.HeaderEncoding = enc;
Response.AddHeader("Content-Disposition",
"attachment;filename=" + filename);
Response.BinaryWrite(buffer);
Response.Flush();
Response.End();

Is it a bug or a feature? ;-)

thx in advance
Bjoern Wolfgardt
 
J

Joerg Jooss

WO70 said:
Hi,

maybe someone had the same problem:
http://support.microsoft.com/kb/895262/en-us

This Hotfix is only available for Windows 2003, but we also use
Windows 2000 and for development Windows XP. So I thought ASP.NET 2.0
will make things better.

And now ASP.NET is there and I found this:
http://msdn2.microsoft.com/en-us/library/system.web.httpresponse.heade
rencoding.aspx

But if I set the Encoding to Unicode, I get this:
'utf-16' cannot be used as Header Encoding

Here is a little testing app:
string filename = "abcdeäüö.txt";

System.Text.UnicodeEncoding enc = new
System.Text.UnicodeEncoding();

Response.ContentType = "text/plain";
Response.Clear();
byte[] buffer ={ 65 };
Response.HeaderEncoding = enc;
Response.AddHeader("Content-Disposition",
"attachment;filename=" + filename);
Response.BinaryWrite(buffer);
Response.Flush();
Response.End();

Is it a bug or a feature? ;-)

It's a bug. HeaderEncoding doesn't work at all -- well, the
undocumented exception in case you try to use UTF-16 is being thrown,
but sadly that's it.

This is a IE bug as well -- Firefox has no problems decoding the UTF-8
encoded header.

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top