How does C # read a Word document? We can use the FileStream object to read the information in the text file, but we can't use this method for Word documents.
In this case, C # to read the implementation of the Word document we need to use the "Microsoft Word 9.0 Object Library" COM component, which provides us with all the objects and methods used to read Word documents.
Here we mainly use the Word.applicationclass method to deal with word applications. The idea is to open the Word document in memory first, and then put the contents of the inside of the entire copy of the Clipboard, and finally the data from the Clipboard to take out.
C # reads the Word document instance code as follows:
Word.ApplicationClass wordApp=new ApplicationClass();
object file=path;
object nullobj=System.Reflection.Missing.Value;
Word.Document doc = wordApp.Documents.Open(
ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
IDataObject data=Clipboard.GetDataObject();
txtFileContent.Text=data.GetData(DataFormats.Text).ToString();
doc.Close();
C # to read the relevant content of the Word document to you here, I hope that you understand and learn C # reading Word documents are helpful.