asp.net 在页面上显示本地的word文档里的内容。

2024-11-27 21:36:35
推荐回答(3个)
回答1:

网上方法不少,可以尝试搜索一下。

第一种方法:
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "Application/msword";
string s=Server.MapPath("E:/wendang/wo582.doc");
Response.WriteFile("E:/wendang/wo582.doc");
Response.Write(s);
Response.Flush();
Response.Close();

第二种方法:
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "Application/msword";
string strFilePath="";
strFilePath =Server.MapPath("E:/wendang/wo582.doc");
FileStream fs = new FileStream(strFilePath,FileMode.OpenOrCreate,FileAccess.Read);
Response.WriteFile(strFilePath,0,fs.Length);
fs.Close();

第三种方法:
string path=Server.MapPath("E:/wendang/wo582.doc");
FileInfo file=new FileInfo(path);
FileStream myfileStream=new FileStream(path,FileMode.Open,FileAccess.Read);
byte[] filedata=new Byte[file.Length];
myfileStream.Read(filedata,0,(int)(file.Length));
myfileStream.Close();
Response.Clear();
Response.ContentType="application/msword";
Response.AddHeader("Content-Disposition","attachment;filename=wo582.doc");
Response.Flush();
Response.BinaryWrite(filedata);
Response.End();

回答2:

建议用PageOffice,可以打开本地word文档并显示在网页上,示例代码在下载包里,有很多

回答3:

网上搜PageOffice有很多示例代码的
你参考下