HTTP headers and non-asci characters (Content-Disposition, filename, attachment) | ActiveX/VBSScript registry editor
ActiveX NT User account manager
Export MDB/DBF from ASP
Url replacer, IIS url rewrite Active LogFile Email export ActiveX/ASP Scripting Dictionary object
| ||
| Article | |||
| Member of ScriptUtils.ByteArray |
The main problem for file downloads is to set right file name with good international characters. The downloaded file name is specified by a filename parametr of Content-Disposition http header.
There is no problem if you set only ASCII characters for the parametr. you can use
Response.AddHeader "content-disposition", "attachment; filename=anyascicharactersyouwant.txt"
But the problem is when you try to use any non-ascii characters in the downoaded file name. Sometimes you will need some russian file name: ???_?????.txt, sometimes chinese 文件名 ???, japanese ファイル名, korean 파일 이름 or some Cental european filename (Czech) příliš_žlutý_kůň_úpěl_ďábelské_ódy.txt.
I was not able to find universal settings to do this task, but it looks like Mozilla based browsers accepts utf-8 encoded headers and headers Encoded Word Extensions from RFC 2231. Internet explorer accepts utf-8 filenames only when 1. the data are URL encoded and 2. the extension of the file contains only ASCII characters.
Content-Disposition - test Non ascii characters
Sub SetContentDisposition(byval FileName) 'set response. charset Response.CharSet = "utf-8" 'set ContentType - download Response.ContentType = "application/download" 'URLEncode the filename for IE If Instr(1, Request.ServerVariables("HTTP_USER_AGENT"), "MSIE", 1)>0 Then FileName = URLEncode(FileName,"utf-8") End If 'Add a Content-Disposition header with the filename Response.AddHeader "Content-Disposition", _ "attachment; filename=""" & FileName & """" End Sub 'URL Encode with character set Function URLEncode(ByVal Data, CharSet) Dim ByteArray Set ByteArray = CreateObject("ScriptUtils.ByteArray") ByteArray.CharSet = CharSet ByteArray.String = Data If Len(Data) > 0 Then Dim I, C, Out For I = 1 To ByteArray.Length C = ByteArray(I)'Asc(Mid(Data, I, 1)) If C = 32 Then Out = Out + "+" ElseIf C < 46 Or c>126 Then Out = Out + "%" + Hex(C) Else Out = Out + Chr(c) End If Next URLEncode = Out End If End Function