Home > DeveloperSection > Articles > Read Microsoft Word Document File by using C#

Read Microsoft Word Document File by using C#

C# C# 
5 Comment(s)
 92607  View(s)
Rate this:

Read Microsoft Word Document File by using C#

It is an efficient way through which we can read Microsoft Word Document file (or .docx extension file) by using C#.Net code.

Here I am making a window form application to read text of MS-Word file (Not image) and showing the ms-word text into windows form richtextbox control. Let’s see the brief demonstration of reading text from ms-word file in c#.

Step 1:  To read MS-Word file write the following code on Read Button click event.

/// <summary>

///This method read the document and writes into richtextbox control 

/// </summary>


        private voidbtn_Read_Click(objectsender, EventArgse)


            // call the method to read ms-word document



/// <summary>

        /// Read ms-word file

        /// </summary>

        public voidReadMsWord()


            // variable to store file path

            string filePath=null;

            // open dialog box to select file

            OpenFileDialog file= new OpenFileDialog();

            // dilog box title name

            file.Title="Word File";

            // set initial directory of computer system

            file.InitialDirectory= "c:\\";

            // set restore directory

            file.RestoreDirectory= true;


            // execute if block when dialog result box click ok button

            if (file.ShowDialog() ==DialogResult.OK)


                // store selected file path






                // create word application

                Microsoft.Office.Interop.Word.Applicationword=new Microsoft.Office.Interop.Word.ApplicationClass();

                // create object of missing value

                object miss= System.Reflection.Missing.Value;

                // create object of selected file path

                object path=filePath;

                // set file path mode

                object readOnly= false;

                // open document                

                Microsoft.Office.Interop.Word.Document docs=word.Documents.Open(refpath, refmiss, refreadOnly, refmiss, refmiss, refmiss, refmiss, refmiss,                                                                                    refmiss, refmiss, refmiss, refmiss, refmiss, refmiss, refmiss, refmiss);

              // select whole data from active window document


                // handover the data to cllipboard


                // clipboard create reference of idataobject interface which transfer the data

                IDataObject data= Clipboard.GetDataObject();

                //set data into richtextbox control in text format


                // read bitmap image from clipboard with help of iddataobject interface

                Image img= (Image)data.GetData(DataFormats.Bitmap);

                // close the document

                docs.Close(refmiss, refmiss, refmiss);


            catch (Exception ex) { MessageBox.Show(ex.ToString()); }



Step 2: After write the above code debug the program and click on Read button

Read Microsoft Word Document File by using C#

When you click on Read button then a file dialog box will be appear for select an ms-word file, after select a file then press Open button.

Read Microsoft Word Document File by using C#

After clicked open button the following output will be appear as follows.

Read Microsoft Word Document File by using C#

Read Microsof Word Documents

By Rohit Kesharwani on   6 years ago
Nice article. It will help a lot.

Re: Read Microsof Word Documents

By Arun Singh on   6 years ago
Thanks Rohit !!!!!

Alternative to read Word files in C#

By James Howard on   5 years ago

nice article!

For ones that are unable to use .NET Word automation, try this C# / VB.NET Word library that doesn't require Word application.

Here is a sample C# read Word:
// Load a document.
DocumentModel document = DocumentModel.Load("Document.docx", DocxLoadOptions.DocxDefault);

// Iterate over all paragraphs in the document.
foreach (Paragraph paragraph in document.GetChildElements(true, ElementType.Paragraph))
    // Iterate over all runs in the paragraph and write their text to console.
    foreach (Run run in paragraph.GetChildElements(true, ElementType.Run))

open .doc file in console application

By Patel Ronak on   2 years ago
sir instead of window Form Application I want to use Console app then pleasae provide code

Read MS Word Document content along with those font format(Bold, Font Color, name. i.e) by using C#

By Parthiban K on   one year ago

As you have mentioned above code is working fine but I need to read content along with those font format like bold, font color, size, background color, track changes etc.., by using c#. Is there any possible way to achieve that? Please let me know if possible.

Warm regards,

Parthiban K

Don't want to miss updates? Please click the below button!

Follow MindStick