Question about the download of a long Chinese file name in Asp.net

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.