Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Programmatically Modifying a Word Document Hosted on a SharePoint

  Asked By: Jordan    Date: Mar 16    Category: Sharepoint    Views: 5955

This will take some explaining and I'm just a casual SharePoint user,
so have mercy on me, OK?

We want to have some Word documents in a SP site, with a broad group
able to search them, but a smaller group able to edit them. To my
knowledge, that's certainly doable.

These Word documents will contain lists of certain things that have
to be done by certain dates. There will be a database that contains
these 'Action Items' and their 'due dates' - the entry of the Action
Items and due dates will be a manual operation. The database will
probably start life as an Access database, but will either be moved
to SQL Server or (much less probably) into SharePoint lists (the back
end of the database).

Now the tricky bits. When an actual completion date is entered for
one of the Action Items, a programmatic series of actions needs to
add a text string to the appropriate Word document.

If SQL Server has been used, a table trigger can be set up to run an
external executable, but the issue then becomes: can SharePoint be
automated to select a file, programmatically open it, insert/append
text and then close the file? Note that this would be done by an
external program, which could lead to all sorts of possible
permission issues. Anyone ever done this sort of thing?

As an alternate, if the back end of the SQL Server database was
implemented as SharePoint lists, could a SharePoint workflow be
configured and triggered by a list item receiving a value - and the
necessary actions of opening up a Word document, adding (appending or
inserting) text and then saving it - be done as part of the workflow?

Or, am I totally out in left field with this concept? Any insights
anyone might have would be most appreciated...



9 Answers Found

Answer #1    Answered By: Joanne Greer     Answered On: Mar 16

Bear with me while I ask some questions about your goals here.

As far as permissions go, you can certainly set  them so that a broad
spectrum of users will be able to read the items  while only a few can
edit them. Those that indeed have read access  to the library will be
able to see these documents  in the result set of a search, so they will
be able to find them.

You start  to lose me with the whole action  items thing being pulled from
database  and then inserting them into a word  document. Why not just
use one of the lists  available to you in SharePoint for this? Depending
on what it is you are trying to create wouldn't a Project or Issue
tracking list  do what you need, without all the back-end coding etc.? An
Issue tracking list would allow you to create a list of items that
needed to be dealt with, assigned to users, set due dates  and track the
actions that are performed on the items etc.

I don't understand why you are seemingly trying to create a Word
document to present list information. If you need to bring information
from different lists into a single presentation source then you could
use a data view web part  to present the items from multiple lists in a
single web part.

Answer #2    Answered By: Cathy Cameron     Answered On: Mar 16

Might I suggest an alternate  approach?

If you are using the 2007 versions of Word and SharePoint there is a
simpler possibility.

1) Use a Tasks list  in SharePoint to store your action  Items

2) Apply a workflow  to the Tasks list that triggers on completion -
the action of which is to set  a metadata property on the Word document
stored in a SharePoint document  Library. You can create such a workflow
with no code using SharePoint Designer. You could also use an event
handler on the Document Library as an alternative to a workflow, or use
Visual Studio to create the workflow but either of those options require
custom code and extra deployment steps to enable in SharePoint.

3) Within Word, expose the metadata property as a string  in the
document itself via a Quick Part - see
for an example.

Answer #3    Answered By: Kerri Steele     Answered On: Mar 16

This looks interesting, didn't know you could do this. When I go
to play with it, Document properties is grayed out for me and so I
cannot choose to insert any metadata column. The post you reference
doesn't give a lot of detail on this function, so, do you have any more

Answer #4    Answered By: Alisha Itagi     Answered On: Mar 16

Not sure why the properties would be grayed out, but here are a couple
other references with some more information.



Answer #5    Answered By: Octavio Dotson     Answered On: Mar 16

Instead of using workflows I would do this programmatically. If using
an SQL server  I would invoke code on the server by writing a custom XML
webservice that would be invoked by the SQL server. If using a
SharePoint List, which would be what I recommend, then create an Event
Handler that will fire whenever an item  in the list  is modified, check
for the Due Date, and if the Due Date is entered programmatically  add
the item to the document. To make adding  the item to the document  easy
I would use one of the open  Office XML based formats supported by Office
2007. Since these are written in XML it would be much easier to
programmatically add items  to the list. Open Office XML documents  are
completely editable and saveable by word  2007.

If you need to save the docs in standard Word format then I would look
at the ASPOSE Word components that make it possible to open, edit  and
save word docs programmatically.

Answer #6    Answered By: Judy Pittman     Answered On: Mar 16

+1 on the APSOSE components. I've used  the Word and PDF components and
found them easy to use. Much simpler than the automation interface to
the Word program.

Answer #7    Answered By: Tricia Mullins     Answered On: Mar 16

In addition, I've tried to use the automation interface in a SharePoint
environment and it doesn't work. It's also a real security problem when
running it on a server.

Answer #8    Answered By: Esha Attlee     Answered On: Jun 20

Well i can tell how you can do this programmatically  

see example @ mysharepointwork.blogspot.com/.../...and-save.html