Summary of methods for reading word documents under asp.net of c

  • 2020-05-12 02:27:16
  • OfStack

Method 1:
 
Response.ClearContent(); 
Response.ClearHeaders(); 
Response.ContentType = "Application/msword"; 
string s=Server.MapPath("C Language reference .doc"); 
Response.WriteFile("C Language reference .doc"); 
Response.Write(s); 
Response.Flush(); 
Response.Close(); 

Method 2:
 
Response.ClearContent(); 
Response.ClearHeaders(); 
Response.ContentType = "Application/msword"; 
string strFilePath=""; 
strFilePath =Server.MapPath("C Language reference .doc"); 
FileStream fs = new FileStream(strFilePath,FileMode.OpenOrCreate,FileAccess.Read); 
Response.WriteFile(strFilePath,0,fs.Length); 
fs.Close(); 

The third method:
 
string path=Server.MapPath("C Language reference .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= The file name .doc"); 
Response.Flush(); 
Response.BinaryWrite(filedata); 
Response.End(); 

Related articles: