用IE打开excel或doc文件出现乱码
代码如下,请请教~
string TmpPath = Server.MapPath( "../upFile/PartLists/200701040115034.xls ");
FileStream fs = new FileStream(TmpPath, FileMode.Open);
BinaryReader bw;
byte[] outbyte = new byte[fs.Length];
fs.Read(outbyte, 0, int.Parse(fs.Length.ToString()));
long FileLength = fs.Length;
Response.Clear();
Response.ContentType = "application/ms-excel ";
Response.AddHeader( "Content-Disposition ", "incline; filename= " + HttpUtility.UrlEncode(Path.GetFileName(TmpPath), System.Text.Encoding.UTF8));
Response.AddHeader( "Content-Length ", FileLength.ToString());
Response.BinaryWrite(outbyte);
Response.End();
------解决方案--------------------------------------------------------
Response.ContentEncoding = System.Text.Encoding.GetEncoding( "GB2312 ");
------解决方案--------------------------------------------------------
HttpUtility.UrlEncode(Path.GetFileName(TmpPath), System.Text.Encoding.UTF8));
改一下这行的编码,或者其他地方有编码的,都改一下 用 GB2312