---
title: "Read Microsoft Word Document File by using C#"  
description: "Read Microsoft Word Document File by using C#This is an efficient way through which we can read Microsoft Word Document file (or .docx extension fil"  
author: "Anonymous User"  
published: 2011-08-29  
updated: 2020-07-19  
canonical: https://www.mindstick.com/articles/629/read-microsoft-word-document-file-by-using-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 3 minutes  

---

# Read Microsoft Word Document File by using C#

## Read Microsoft Word Document File by using C#

This 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 the 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](https://www.mindstick.com/articles/996/select-all-checkbox-from-header-checkbox) text from an ms-word file in c#.

**Step 1:** To read MS-Word file write the following code on reading 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            ReadMsWord();         }/// <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                filePath=file.FileName.ToString();                        }               try            {                   // 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                 docs.ActiveWindow.Selection.WholeStory();                 // handover the data to cllipboard                  docs.ActiveWindow.Selection.Copy();                 // clipboard create reference of idataobject interface which transfer the data                 IDataObject data= Clipboard.GetDataObject();                 //set data into richtextbox control in text format                 richTextBox2.Text=data.GetData(DataFormats.Text).ToString();                 // 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 writing the above code debug the program and click on the Read button

![Read Microsoft Word Document File by using C#](https://www.mindstick.com/mindstickarticle/5cd1b721-9b94-4ea0-bd6e-2bb157401069/images/49d6d859-4230-4133-9e17-253fd54ae1a0.png)

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

![Read Microsoft Word Document File by using C#](https://www.mindstick.com/mindstickarticle/5cd1b721-9b94-4ea0-bd6e-2bb157401069/images/35230f56-4812-45f5-8aca-2f1b71f4ab9c.png)

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

![Read Microsoft Word Document File by using C#](https://www.mindstick.com/mindstickarticle/5cd1b721-9b94-4ea0-bd6e-2bb157401069/images/cf4f65e7-bede-4f7b-9c47-f99dc8177255.png)

\

---

Original Source: https://www.mindstick.com/articles/629/read-microsoft-word-document-file-by-using-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
