Home > c#, OpenXml > Retrieve the content of Microsoft Word document using OpenXml and C#

Retrieve the content of Microsoft Word document using OpenXml and C#

One of the tasks involves me to retrieve the contents of Microsoft Word document (word2007 above). I try to search for some resources online with not much luck; most of the examples are for writing contents to word document using OpenXml. I decide to blog this as my reference and hopefully people who read this post will find it useful as well.

To retrieve the contents of Microsoft Word document using XML is extremely simple.

1. Firstly, you need to download and install the Open XML SDK 2.0 for Microsoft Office. (Download link)

2. Create a Console application then add the DocumentFormat.OpenXml.dll and WindowsBase.dll to the project, you can find these dlls in the .NET tab of the Add Reference window.

3. Write the following code to grab the contents from the word document and display it on the console window.

4. To write contents to Word document is very easy too.All you have to do is follow:

You can download the complete source code here.

References:

Getting Started with the Open XML SDK 2.0 for Microsoft Office

Walkthrough: Word 2007 XML Format

Word Processing How To

Open XML SDK 2.0 for Microsoft Office

Office Developer Center

openxmldeveloper

Open XML Package Explorer

How to: Open and Add Text to a Word Processing Document

Advertisements
  1. December 29, 2011 at 7:53 pm

    thank u very much.. if u explain content controls also.. i.e very fine with me.

  2. RajeshSingh
    February 22, 2012 at 4:52 am

    Really this is a good article, which helps a lot for beginners as me as well as developer. Check the following link too its having nice post on create microsoft word document using c# code.

    http://www.mindstick.com/Articles/a25ba73f-324d-4926-93b5-89460f77621d/?Create%20Microsoft%20Word%20Document%20by%20using%20C#

    Thanks Everyone for your nice post.

  3. suchithra
    July 9, 2012 at 5:01 pm

    nice post .i want to know how can i update the existing doecument means replace few contents in the mid of document

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: