According to the test, the filename in the header can contain only 18 Chinese characters and 165 English letters.
One in utf8 contains nine bytes (the system. Text. unicodeencoding. utf8.getbytecount () method returns 3 characters for each Chinese character), which should be 18*9 = 162 <165)
Therefore, do the following when downloading long Chinese file names:
When the file name getbytecount is greater than 57 (the combination of Chinese and English is not determined), the file name is truncated.
Dim fullfilename as string = server. mappath ("qbuttom3.aspx/http://www.cnblogs.com/") & "Temp \" & filename
If system. Io. file. exists (fullfilename) = true then
Dim strlenth as integer = system. Text. unicodeencoding. utf8.getbytecount (modname)
If strlenth> 57 then
Modname = modname. substring (0, 17) + "_.xls"
End if
Response. Clear ()
Response. contenttype = "application/vnd. ms_excel"
Response. appendheader ("content-disposition", "attachment; filename =" & server. urlencode (modname ))
Response. Flush ()
Response. writefile (fullfilename)
End if
Note:
In many cases Program Server is used. htmlencode and server. after urlencode first encodes Chinese characters, the system still displays garbled characters. According to Microsoft's explanation, this situation is related to IIS. The reason Microsoft provides is that IIS without pack3 assumes that each character contains two bytes, some utf8 characters use three bytes. In this way, the created buffer is too small to accommodate these bytes, leading to garbled characters. The solution is to pack3 for IIS.
As follows:
Download q249831_w2k_sp3_x86_en.exe now
Chinese (simplified ):
Download q249831_w2k_sp3_x86_cn.exe now