加Response.Charset = "UTF-8"
Response.ContentEncoding = System.Text.Encoding.Default
就可以了,我也正郁闷为什么点打开时会再出一次确认框呢~~~~~~~~~

解决方案 »

  1.   

    参考一下
    HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=export.xls");
    HttpContext.Current.Response.Charset ="UTF-8";
    HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.Default;
      

  2.   

    HttpContext.Current.Response.Charset ="UTF-8";
    应该是能解决的
      

  3.   

    用Response.AddHeader("Content-Disposition", "inline; filename=" + System.Convert.ToChar(34) + filename + System.Convert.ToChar(34))
    Response.ContentType = "application/zip"
    可解决二次对话问题!!!
      

  4.   

    private void ToEXCEL(System.Web.UI.Control ctl) 

    Response.Charset="GB2312"; 
    Response.AppendHeader("Content-Disposition","attachment;filename=myExcel.xls");  
    Response.ContentEncoding = System.Text.Encoding.UTF8;
    Response.ContentType = "application/ms-excel"; ctl.Page.EnableViewState = false; 
    System.IO.StringWriter tw = new System.IO.StringWriter(); 
    System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(tw);  ctl.RenderControl(hw);  Response.Write(tw.ToString()); 
    Response.End(); 
    }
      

  5.   

    贴出来看看,实在不行设一下IE设置里的高级,总是以UTF-8发送Url是否打钩。
      

  6.   

    代码如下: Response.AppendHeader("Content-Disposition","attachment;filename="+HttpUtility.UrlEncode(myExcel)+".xls"); 
    Response.Charset="";  
    Response.ContentEncoding = System.Text.Encoding.UTF8;
    Response.ContentType = "application/ms-excel";
    ctl.Page.EnableViewState = false; 
    System.IO.StringWriter tw = new System.IO.StringWriter(); 
    System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(tw); 
    ctl.RenderControl(hw); 
    Response.Write(tw.ToString()); 这种是下载的保存对话框在2000系统下显示正确的中文,而在XP系统下是乱码,对话框仍然是弹出两次
      

  7.   

    public static void DownloadFile( System.Web.UI.Page refPage, string _FilePath)
    {
    try
    {
    string MyContentType = "";
    if(!System.IO.File.Exists(_FilePath)){
    throw(new Exception("不存在的文件"));
    }
    Stream iStream=new FileStream(_FilePath,FileMode.Open,FileAccess.Read,FileShare.Read); long lngFileLength=iStream.Length;
    FileInfo fileinfo = new FileInfo(_FilePath);
    String FileName = fileinfo.Name;
    switch ( FileName.Substring( FileName.LastIndexOf( "." ), 4 ) )
    {
    case ".xls":
    MyContentType = "application/vnd.ms-excel";
    break;
    case ".doc":
    MyContentType = "application/msword";
    break;
    case ".htm":
    MyContentType = "text/html";
    break;
    default:
    MyContentType = "application/zip";
    break;
    }


    refPage.Response.Clear();
    refPage.Response.AddHeader( "Content-Type", MyContentType );
    refPage.Response.AddHeader("Content-Disposition", "inline;filename="+ System.Convert.ToChar(34) + System.Web.HttpUtility.UrlEncode( System.Text.Encoding.UTF8.GetBytes( FileName ) ) + System.Convert.ToChar(34) );
    refPage.Response.AddHeader("Content-Length", fileinfo.Length.ToString() );
    refPage.Response.Flush(); byte[] Buffer;
    bool ClientClosed=false;
    int BufferLength=Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["BufferLength"]);

    int Len=1;             

    while (Len>0 && ClientClosed==false)
    {
    Buffer= new Byte[BufferLength];
    Len = iStream.Read(Buffer, 0, BufferLength);
    refPage.Response.OutputStream.Write(Buffer,0,Len);
    refPage.Response.Flush();
    ClientClosed=!refPage.Response.IsClientConnected;
    }
    iStream.Close();
    iStream=null;
    refPage.Response.End();
    }
    catch( Exception excep )
    {
    throw(excep);

    }
    }
      

  8.   

    我们在下载时处理是将文件截取前32个字节,这样的话就不会错了.(如果不想这样做处理的话,可以UPDATE一下系统,由系统自己去做吧.)
      

  9.   

    我不是很懂qiren5761(杞人)的意思,请指教
      

  10.   

    我的:
                filename = Request.QueryString("title") & ".xls"
                filename = System.Web.HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(filename))            Response.ContentType = "application/vnd.ms-excel"
                ' 从Content-Type header中去除charset设置
                Response.Charset = ""
                Response.AddHeader("Content-Disposition", "attachment;filename=" & System.Convert.ToChar(34) & filename & System.Convert.ToChar(34))
                Response.Charset = "UTF-8"
                Response.ContentEncoding = System.Text.Encoding.Default            Me.EnableViewState = False
                Dim tw As New System.IO.StringWriter
                Dim hw As New System.Web.UI.HtmlTextWriter(tw)            DataGrid1.RenderControl(hw)
                Response.Write(tw.ToString())
                Response.End()
    你还是加上filename = System.Web.HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(filename))吧
      

  11.   

    不过直接打开后,excel里面的文件名还是乱的,保存打开就没问题,谁有办法?呵呵~~
      

  12.   

    乱码的问题原来和“IE设置里的高级,总是以UTF-8发送Url是否打钩”这个有关。算是解决了。