欢迎来到我的地盘:今天是

若得山花插满头,莫问奴归处!

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

经测试,在header中的filename 中文只能18个,英文165个
按中文一个在UTF8里是9个字节( System.Text.UnicodeEncoding.UTF8.GetByteCount()方法获取每个中文为3个字符),应该是18*9=162<165)
因此在长中文文件名下载时做以下处理:
当文件名GetByteCount大于57时(没有判断中英文混合的情况)则截取文件名
        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
注:
许多情况下当程序采用了Server.HTMLEncode 和 Server.URLEncode 先对中文进行过编码以后,系统依然显示乱码,根据微软的解释,这种情况跟IIS有关,微软提供的原因是未打Pack3的IIS 假定每个字符两个字节,而某些 UTF8 字符使用三个字节。这样,所创建的缓冲区太小,无法容纳这些字节,导致产生乱码,解决方法就是给IIS打Pack3
下载地址如下
 :
立即下载 Q249831_w2k_sp3_x86_EN.exe

中文(简体):
立即下载 Q249831_w2k_sp3_x86_CN.exe

posted on 2007-12-20 15:10  莫问奴归处  阅读(635)  评论(0编辑  收藏  举报
轩轩娃