Thursday, 12 April 2012

Programmatically edit text in word document of sharepoint 2010 document library


I was looking for good solution to one of our long term problems to add a footer message in each word document page of our existing 3000 documents in our document library. I knew that doing this progmatically would be the best way but i was looking for a good feasible code.

So here is what i did
1. Created a timer job. This was deployed in farm as global but was hard-coded to run on just one web app. We didn't wanted to overload the server.
2. Adding the code in my timer job referencing the below posts -

 * programmatically Open and save documents in document library SharePoint - From this post i got the basic idea of retrieving word docs from sharepoint and then getting the word doc as object using Open XMl SDK. This allowed me to open the word doc in edit mode atleast. The post clearly defined how to open a word doc from SharePoint, edit it and Save it back. Next I was looking for a way to add Footers only and the below msdn post was more than helpful.

* Generating Documents with Headers and Footers in Word 2007 by Using the Open XML SDK 2.0 for Microsoft Office - This post clearly states about how to create Header and Footer parts in the document. Its a great document to follow.

and finally combining both the posts i was able to create a complete solution. I will soon post my code for download.

Ads by Google

1 comment:

  1. Thanks for the Information, But i dont Understand this:
    Created a timer job. This was deployed in farm as global but was hard-coded to run on just one web app. We didn't wanted to overload the server.

    See its easy these days , to Make Timer Job Dynamic. You can cick them from an Admin Page.... Believe me i run many Dynamic and Configurable Non-HardCoded Timer Jobs....

    ReplyDelete