Read A Microsoft Word Document in C#

Learn to read a word document file using C# .NET. Microsoft Word 9.0 object library is the only reference we have to add. This provides the neccesity to perform this tasks.

The code required is given below:

Word.ApplicationClass wordApp=new ApplicationClass();
//Word.ApplicationClass is to access the word application

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


it is done:
This is a small example to work with the reading of .doc file through c#.net.
cheers....

By alice johnson   Popularity  (3139 Views)