现在的位置: 首页 > 综合 > 正文

asp.net 读取word 文档的方法

2013年01月17日 ⁄ 综合 ⁄ 共 1071字 ⁄ 字号 评论关闭

第一种方法:
   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

;

   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();

【上篇】
【下篇】

抱歉!评论已关闭.