views:

223

answers:

2

Is it possible to edit and insert entries in a word document that is hosted on SharePoint?

I need to fill in a reviewer's table based on who made the last change to the document.

I know I would use an event receiver to do this, but how do I interact with the word document interactively?

A: 

You can use the SPDocumentLibrary class and the method GetItemsInFolder to return a SPListItemCollection.

From there you can cast an item to a Word object and manipulate it through the word object model

Rob
This does, however, require that Word is installed on the <b>server</b>, right?
vinny
Oops! your quite right. An alternative could be to use the sharepoint webservice to retrieve a document and work on it on your local machine (with Word installed) and then save it back to the server.
Rob
+2  A: 

You want to use the an SPListItem's CreatedBy or ModifiedBy values and the OpenXml API to do this so you do not have to use the Word Object Model on the WSS/MOSS Server.

To obtain the user information, you'll want to to something like this.

//get the SPWeb reference for web
SPFile updatedFile= web.GetFile(fileUrl);
SPUser author = updatedFile.Author; //or updatedFile.ModifiedBy for modifier

Once you have the author, to update the Word document, you can refer to this SharePoint and OpenXml wiki page for some assistance. This is based on Eric White's blog (and others) with Open Xml. I highly suggest you read his blog and look at the PowerTools for OpenXml Codeplex project for some code that will definitely be helpful.

Also see OpenXmlDeveloper and Open XML Developer portal for more information

Hope this helps.

Pete Skelly
Excellent, thanks!
LB