public bool LoadDownFile(string FileName,string ClientFileName,System.Web.UI.Page page)
{
try
{
string type = FileName.Split('.')[1];
FileInfo fileinfo = new FileInfo(FileName);
FileStream stream = File.OpenRead(FileName);
byte[] fb = new byte[fileinfo.Length];
stream.Read(fb,0,fb.Length);
System.Web.HttpResponse rps = page.Response;
rps.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
rps.Charset = "utf-8";
rps.BufferOutput=false;
rps.ContentType="application/" + type;
ClientFileName = System.Web.HttpUtility.UrlEncode(FileName).Replace("+","%20");
rps.AppendHeader("Content-Disposition", "attachment;FileName=" + ClientFileName);
rps.ContentType = "application/octet-stream"; 
rps.BinaryWrite(fb);                    
stream.Close();
}
catch(Exception)
{
return false;
}
return true;
}

解决方案 »

  1.   

    已经统一成了UTF8但还是乱码.
      

  2.   

    http://www.cnsdn.com.cn/inc/show.asp?id=1537
      

  3.   

    http://www.netbei.com/Article/aspx/aspx6/200501/3223.html
      

  4.   

    给你个下栽函数:
    private void LoadFile(string FilePath,string FileName)
    {
    try
    {
    string strFile=FilePath;
    if(!System.IO.File.Exists(strFile))
    {
    return;
    }
    Response.Clear();
    Response.ClearHeaders();
    Response.Charset = "utf-8";
    Response.ContentEncoding =System.Text.Encoding.UTF8;
    Response.ContentType = "application/octet-stream"; 
    FileInfo fi=new FileInfo(strFile);
    Response.AddHeader("Content-Disposition","attachment;  filename="  +  HttpUtility.UrlEncode(FileName)) ;
    Response.AddHeader("Content-Length",fi.Length.ToString());
    byte[] tmpbyte=new byte[1024*8];
    FileStream fs=fi.OpenRead();
    int count;
    while((count=fs.Read(tmpbyte,0,tmpbyte.Length))>0)
    {
    Response.BinaryWrite(tmpbyte);
    Response.Flush();
    }
    fs.Close();
    Response.End();
    }
    catch(Exception err)
    {
    throw new Exception("文件下载失败"+err.Message);
    }
    }