aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Read Data From MS Word File (Document) in Asp.Net using C#, VB.Net

Jun 8, 2016

Here I will explain how to read from ms word file in using c#, with example or how to read data from word document in using c#, with example or how to read word document in using c#, with example. By using “Microsoft.Office.Interop.Word” reference in application we can read data from word file / document using c#,

To read data from word document file in first create new word document file in your system and write some content in that to read like as shown below

Now in visual studio create new website and open your aspx page and write the following code

<html xmlns="">
<head runat="server">
<title>How To Read MS Word File in Asp.Net using C#, VB.Net</title>
<form id="form1" runat="server">
Read Word Document in ASP.Net using C#.Net & VB.Net</h2>
<td>Select Word File
<td><asp:fileupload id="fileupload1" runat="server"></asp:fileupload></td>
<td><asp:button id="btnRead" onclick="btnRead_Click" runat="server" text="Read Document"></asp:button></td>
<td colspan="2">Content of Word Document:
<td colspan="2"><asp:textbox height="500px" id="txtread" runat="server" textmode="MultiLine" width="100%"></asp:textbox>
After completion of adding aspx page code now we need to add “Micrsoft Office Object Library” reference to our application because to read word document we need to Microsoft word library reference to our application.

To add reference right click on your application à select add reference à Go to COM section à from that Microsoft Office Object Library à Click OK like as shown below.

Here you don’t need to worry about version of Microsoft Office Object Library because it will vary based on word installed on your computer.

After adding Microsoft word library reference now open code behind file and add following namespaces

C# Code

using System;
using System.Web;

After completion of adding namespaces you need to write the code like as shown below

protected void btnRead_Click(object sender, EventArgs e)
object filename = Server.MapPath(fileupload1.FileName);
Microsoft.Office.Interop.ApplicationClass mswordappcls = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document msworddoc = new Microsoft.Office.Interop.Word.Document();
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
msworddoc = mswordappcls.Documents.Open(ref filename, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible);
txtread.Text = msworddoc.Content.Text;


Partial Class VBCode
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

End Sub
Protected Sub btnRead_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim filename As Object = Server.MapPath(fileupload1.FileName)
Dim mswordappcls As Microsoft.Office.Interop.ApplicationClass = New Microsoft.Office.Interop.Word.ApplicationClass()
Dim msworddoc As New Microsoft.Office.Interop.Word.Document()
Dim [readOnly] As Object = False
Dim isVisible As Object = True
Dim missing As Object = System.Reflection.Missing.Value
msworddoc = mswordappcls.Documents.Open(filename, missing, [readOnly], missing, missing, missing, missing, missing, missing, missing, missing, isVisible)
txtread.Text = msworddoc.Content.Text
End Sub
End Class


Following is the demo of our application to read word document content in using

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Brijender Ahuja said...

Why to use com components? We can use OpenOffice XML instead. Com based components have lots of machine dependencies that can be faced while deploying this application to different server and same version of ms word software must be installed on that server.

Dhiru said...

C# code generating following error:
The type or namespace name 'ApplicationClass' does not exist in the namespace 'Microsoft.Office' (are you missing an assembly reference?)

Plz help

Kirthi Vasu said...

Thanks sir

Zohaib Hassan said...

ApplicationClass does not exist. What is this ?? Please help

Give your Valuable Comments

Other Related Posts

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.