我已经在web.config文件里面指定了
<globalization requestEncoding="gb2312" responseEncoding="gb2312" fileEncoding="gb2312" />
在导出的文件里面也指定了:
HttpResponse resp;
resp=Page.Response;
resp.ContentEncoding=System.Text.Encoding.Default;//gb2312也试过了
resp.AppendHeader("Content-Disposition", "attachment;filename=报表.xls"); 导出的文件名老是显示乱码啊,怎么办呢?

解决方案 »

  1.   


    Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + Server.UrlEncode(fileName) 
    <a href="YourDownload.aspx/嘎嘎嘎.xls?fileid=12345">嘎嘎嘎.xls</a>
      

  2.   

    试试下面的
    "attachment;filename=" + Server.UrlPathEncode("报表.xls",System.Text.Encoding.UTF-8)
      

  3.   

    HttpUtility.UrlPathEncode(文件名)
    试试看可以么
      

  4.   

    Response.AddHeader("Content-Disposition", "attachment; filename="+System.Web.HttpUtility.UrlEncode("中文",System.Text.Encoding.UTF8)+".xls");
      

  5.   

    参考一下:
    web.config
    <globalization requestEncoding="GB2312" responseEncoding="GB2312" uiCulture="zh-CN" culture="zh-CN" fileEncoding="GB2312" />后台:
    using System.Globalization;
    using System.IO;
    using System.Text;HttpResponse response = HttpContext.Current.Response; 
                 
    response.Charset = "GB2312"; 
    response.ContentEncoding = Encoding.GetEncoding("GB2312"); 
    response.ContentType = "application/ms-excel/msword"; 
    response.AppendHeader("Content-Disposition", "attachment;filename=" +  
    HttpUtility.UrlEncode("测试.xls")); 
     
    CultureInfo cult = new CultureInfo("zh-CN", true); 
    StringWriter sw = new StringWriter(cult);             
    HtmlTextWriter writer = new HtmlTextWriter(sw); 
     
    writer.WriteLine("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=GB2312\">"); 
    DataGrid1.RenderControl(writer); 
    Response.Write(sw.ToString());
    Response.End();
      

  6.   

    to xiahouwen(武眉博<活靶子.NET>):
    用Server.UrlEncode还是乱码,不过感觉和一起的乱码不太一样了。to lazyfish(呆呆虫):
    Server.UrlPathEncode只能是一个参数,Server.UrlPathEncode("报表.xls)这样就可以了。to xiaofeizhu():
    你的方法可以。
      

  7.   

    LoveCherry的可以,看来要想不出现乱码,可以用下面2种简单的方法:1.用System.Web.HttpUtility.UrlEncode或者Server.UrlEncode方法,不过要2个参数都写上:
    System.Web.HttpUtility.UrlEncode("报表",System.Text.Encoding.UTF8)+".xls");2.用HttpUtility.UrlPathEncode方法,只要写一个参数就可以了:
    HttpUtility.UrlPathEncode("报表.xls")谢谢各位的讨论。