读书人

用IE打开excel或doc文件出现乱码,该怎

发布时间: 2012-01-15 22:57:49 作者: rapoo

用IE打开excel或doc文件出现乱码
用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

读书人网 >asp.net

热点推荐