Reader Level:

Reading a word document using C#

By Krishnan LN on Feb 27, 2006
This tutorial is basically for C# beginners. It describes how to read a word document using C#.

We may have used FileStream to read text from a text file but not the same way for getting text from a word document.

We have to use a Microsoft COM component called "Microsoft Word 9.0 object library" which provides classes and methods to read from a word document.

We have to use Word.ApplicationClass to have access to the word application.

Open the word document in memory, copy all the content to the clipboard and then we can take the data from the clipboard.

The code required is given below:

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



IDataObject data=Clipboard.GetDataObject();



Article Extensions
Contents added by adil khan on Sep 24, 2012
Contents added by thai ho on Mar 13, 2010

hi Krishnan.L.N your ex project is very good, but can you keep read the document and keep it's format and display it's format

Krishnan LN
Krishnan LN

Krishnan L. N. is working in Cognizant, Chennai, INDIA. He has 7 years experience working with Microsoft .NET technologies.



Spire.Doc - Free .NET Word API
Use Spire.Doc to create, read, write, print, and convert word documents to OpenXML, RTF, TXT, XPS, EPUB, EMF, HTML, Image and PDF.

Trending up