About ASP.NET Chinese file name long download problem

xiaoxiao2021-03-06  57

After testing, FileName in Head can only be 18, and 165 in English is 9 bytes in the UTF8 (System.Text.UnicodeEncoding.utf8.getbytecount () method Get each Chinese for 3 characters) It should be 18 * 9 = 162 <165) Therefore, do the following processing when the long Chinese file name is downloaded: When the file name getBytecount is greater than 57 (there is no judgment of the case in English mixing), the file name DIM FULLFILENAME AS STRING = Server is intercepted. Mappath ("qbuttom3.aspx /../../") & "Temp /" & FileName if system.io.file.exists (fullfilename) = true kil swab.UnicodeEncoding.utf8.GetbyteCoding.utf8.GetBytecOtemN (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 () Response.flush () response.writefile (FullFileName) End if Note: Many cases of Server.htmlencode and Server.htmlenCode and Server.urlencode are first After encoding, the system still shows garbled, according to Microsoft's explanation, this situation is related to IIS, the reason for Microsoft provides the IIS that is not picked by IIS assumes two bytes of each character, and some UTF8 characters use three bytes. In this way, the buffer created is too small, which cannot accommodate these bytes, resulting in garbled, the solution is to play the Pack3 download address for IIS: immediately download Q249831_W2K_SP3_X86_EN.EXE Chinese (Simplified): Download Q249831_W2k_sp3_x86_cn.exe

转载请注明原文地址:https://www.9cbs.com/read-113635.html

New Post(0)