+ -
当前位置:首页 → 问答吧 → 怎样把word文档直接显示在浏览器中

怎样把word文档直接显示在浏览器中

时间:2011-12-14

来源:互联网

怎样把word文档直接显示在浏览器中(用c#语言)!
谢谢!

作者: lixiaohong123   发布时间: 2011-12-14

http://ufo-crackerx.blog.163.com/blog/static/11307877820111017113958413/

作者: crackdung   发布时间: 2011-12-14

有具体的c#代码吗?我需要用编程来实现!
谢谢!

作者: lixiaohong123   发布时间: 2011-12-14

第一种方法:
  Response.ClearContent();
  Response.ClearHeaders();
  Response.ContentType = "Application/msword";
  string s=Server.MapPath("C#语言参考.doc");
  Response.WriteFile("C#语言参考.doc");
  Response.Write(s);
  Response.Flush();
  Response.Close();
第二种方法:



  Response.ClearContent();
  
  Response.ClearHeaders();
   
  Response.ContentType = "Application/msword";  

  string strFilePath="";  

  strFilePath =Server.MapPath("C#语言参考.doc"); 
  
  FileStream fs = new FileStream(strFilePath,FileMode.OpenOrCreate,FileAccess.Read);
   
  Response.WriteFile(strFilePath,0,fs.Length); 

  fs.Close(); 

第三种方法:

string path=Server.MapPath("C#语言参考.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=文件名.doc"); 

  Response.Flush(); 

  Response.BinaryWrite(filedata); 

  Response.End(); 

作者: hefeng_aspnet   发布时间: 2011-12-14

只可惜需要安裝office,,,呵呵呵呵呵呵呵呵呵

作者: crackdung   发布时间: 2011-12-14

买控件,用SOAOFFICE,或者转化成HTML,直接显示。

作者: goushibin   发布时间: 2011-12-14

热门下载

更多