SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to connect SP and Word. The Microsoft tutorial on this issue does this:

ClientContext clientContext = new ClientContext("http://MyServer/sites/MySiteCollection/MyWebSite");

How can I have SP pass the URL to Word instead of hard coding it like the above example does? Note that Word ALREADY does this somehow, since if you click 'New Document' in the document library, it passes info to Word (e.g. go to Insert->QuickPart->Document Property). It would also answer my question if you can tell me how to reference the information that SP already sent Word (I just need a handle on the URL information without hardcoding it... it'd be nice to use the information that SP already sent to Word, but if I have to requery it that works too).

If you can tell me how to get that information both ways, bonus points to you for being so awesome.

share|improve this question
Instead of doing the above, I used WCF/REST and queried the SP Web Services using a VS settings file to store my URL so it can be changed later when I move to production... – KyleM Jul 26 '11 at 19:48
Can you post this as the answer or can we delete this question? – Kit Menke Aug 1 '11 at 18:49
@kit, actually the answer to this question would be VERY useful and informative because it would explain how communication operates between Word and SharePoint. My alternate solution gets around the problem, but it does not answer the question. IF I had enough reputation here I'd start a bounty, sometimes it seems like difficult questions get ignored here without one.... – KyleM Aug 1 '11 at 23:38
Hmm maybe this would be a good candidate for our "question hitlist" we are planning! – Kit Menke Aug 2 '11 at 1:09
@Kit I quite agree. Perhaps this site could form some sort of partnership with MSFT where a limited amount of questions could be forwarded to their experts on a monthly basis. Thanks a lot for your replies. :) – KyleM Aug 2 '11 at 3:01

I can help a little, I think. When you upload a doc to SharePoint, SharePoint injects that doc with a bunch of XML. You can tap into this XML with Word's content controls. The result: an interface in Word that lets you edit XML data, then if you upload to SharePoint, SharePoint can recognize and sync your data in its column headers. If you edit and then download, you'll notice the info goes both ways: Word -> SharePoint and SharePoint <- Word. You can pass your URL back and forth this way.

To accomplish this, do the following:

1) Make a doc library in SharePoint.

2) Create a custom column "Big Test" <--- or whatever you want.

3) Create a new doc. Drop in a plain text content control. (On Word's ribbon, it's Developer -> Plain Text content control.)

4) With the content control still selected, click Developer -> Properties and give your content control the title and tag "Big Test Content Control" (or whatever you want). Save and close.

5) Upload your test doc to your doc library.

6) Download that doc. It's now been injected with the XML you need.

7) Download the Word Content Control Toolkit. Install it and open it.

8) Open your doc in the Toolkit. On the right, under "Namespace", select "".

9) Expand properties -> documentManagement. You should see your custom column header under documentManagement ("Big Test" if you followed this perfectly so far). Here's a look at some of the XML SharePoint injected.

10) Find your content control on the left. It will be called "Big Test Content Control" if you didn't provide your own name.

11) Drag and drop the "Big Test" tag onto the "Big Test Content Control". If done correctly, it will turn bright blue.

12) Save and close the Toolkit.

13) To test, reopen the doc through Word. Try putting a value in your content control, then saving and uploading the SharePoint. The custom column you put in should have correctly updated. If you then modify the data in the column and redownload the doc, then content control will update as well.

You already discovered that Insert -> Quickparts -> Document Property can do this faster, but the Toolkit should provide some more insight about what's going on in the background.

Good luck.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.