asp.net c#怎么读取word文件并在web中显示
asp.netc#怎么读取word文件并在web中显示HELPME!!!!能不能给我一个完整的例子呢?你说的那个file.FILENAME不懂,还有那个文件流,也不懂.以...
asp.net c#怎么读取word文件并在web中显示
HELP ME!!!!
能不能给我一个完整的例子呢?
你说的那个file.FILENAME不懂,还有那个文件流,也不懂.
以下是我的测试:
FileStream fs = new FileStream("e:\\编委说明.doc", FileMode.Open, FileAccess.Read);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/msword";
Response.AddHeader("Content-Disposition", "attachment;filename=" +
HttpUtility.UrlEncode("e:\\编委说明.doc").Replace("+", "%20"));// 防止乱码
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.BinaryWrite(bytes);
Response.End();
结果是乱码.
我又换了一下代码:
把这句HttpUtility.UrlEncode("e:\\编委说明.doc").Replace("+", "%20"));// 防止乱码
换成:
HttpUtility.UrlEncode(bytes).Replace("+", "%20"));// 防止乱码
结果是下载文件到本地机器,这个不是我用要的结果,我要直接在页面中显示文件内容 展开
HELP ME!!!!
能不能给我一个完整的例子呢?
你说的那个file.FILENAME不懂,还有那个文件流,也不懂.
以下是我的测试:
FileStream fs = new FileStream("e:\\编委说明.doc", FileMode.Open, FileAccess.Read);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/msword";
Response.AddHeader("Content-Disposition", "attachment;filename=" +
HttpUtility.UrlEncode("e:\\编委说明.doc").Replace("+", "%20"));// 防止乱码
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.BinaryWrite(bytes);
Response.End();
结果是乱码.
我又换了一下代码:
把这句HttpUtility.UrlEncode("e:\\编委说明.doc").Replace("+", "%20"));// 防止乱码
换成:
HttpUtility.UrlEncode(bytes).Replace("+", "%20"));// 防止乱码
结果是下载文件到本地机器,这个不是我用要的结果,我要直接在页面中显示文件内容 展开
1个回答
展开全部
Response.ContentType = "application/msword";
Response.AddHeader("Content-Disposition","attachment;filename=" +
HttpUtility.UrlEncode(file.FILENAME).Replace("+","%20"));// 防止乱码
Response.Charset="UTF-8";
Response.ContentEncoding=System.Text.Encoding.Default;
Response.BinaryWrite(文件流);
Response.End();
Response.AddHeader("Content-Disposition","attachment;filename=" +
HttpUtility.UrlEncode(file.FILENAME).Replace("+","%20"));// 防止乱码
Response.Charset="UTF-8";
Response.ContentEncoding=System.Text.Encoding.Default;
Response.BinaryWrite(文件流);
Response.End();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询