Monday, March 02, 2009

MOSS 2007 - Show SharePoint Version Number in MS Word Documents

UPDATE: I've just verified this technique also works with SharePoint 2010. Also keep in mind this technique only seems to work for documents in MS Word 2007 .docx format. I assume it will also work in MS Word 2010, but I have not tested that yet.

UPDATE 2: I should have posted this sooner, but I have run into problems on SharePoint 2010 with sites that are heavily customized (sites from MOSS 2007 that had been heavily customized before being upgraded to 2010, then copied to create new sites) getting versioning to work as described below. I havent been able to determine what the problem is or how to fix it yet.

One of the requirements here at work is that we normally save the current "version number", which is user entered and maintained, into word documents that go out to clients. At some point, someone ends up forgetting to update the version number and version history, but they always have to enter that information into SharePoint when they check the document in. So, how can we automatically insert that information into a word document from SharePoint?

Sadly, there is no easy "out of the box" way to do this. The version number you see in the properties of a word document is MS Word's own internal version number that does not relate to the SharePoint version number in any way.

One solution I've found to work well is setting up an information policy on the document library in order to enable labels. You can then define a label that displays the current version number, which you can then insert into a MS Word 2007 document as an image (it seems to look best in the document footer, imo). Here's how:

  1. Create a new document library or modify an existing one
  2. In the library settings, under "Advanced Settings" set "Allow management of content types?" to "yes".

  3. Enable versioning (it does not matter if you do minor versions or not).

  4. Create a new information policy on the library, and select the content type you want the label to be available to (I use the default "document" type).

  5. Define a new policy, check "Enable Labels". Do not check the other two options Below it. In the "Label format" field, enter something like "SharePoint Version Number: {Version}". {Version} is the field that will display the version number. Modify the "Appearance" settings to suit your needs, then click "OK".

I typically set the size of the label to something thin, like .5 inches, so I can tuck it into the footer of the word document and still keep the footer small. Now, the label will not automatically show up in your documents, you still need to insert the label yourself. And so far, it seems this feature only works with Word 2007 documents, my 2003 word documents just display a field name rather than a number. Anywho, to setup your word document:

  1. Create a new document in the library.
  2. Save the new word document as a word 2007 file (.docx format) in the library.

  3. Check out and edit the word 2007 document, click the "insert" tab in the ribbon, then click "Quick Parts" in the "Text" button group. Under "Document Properties" click on "Label" to insert your SharePoint label as an image.

  4. save your document, checkin and close word 2007. Then re-open the document and you should see the label change to the actual SharePoint version number of the document.

..and one last thought - Since the format of the text for the version number label might change due to personal preference (some might want to use "SharePoint Version Number: x", while others use "Version: x") it may be a good idea to simply display the version number only, as a small image by itself with no additional text. This way the document author has more control over how the version number is displayed and described in their document.


mcmerlla said...

I've tried this, but when I look in the Quick Parts menu, the Document Property option is greyed out. When I instead use Insert > Label, the SharePoint Version number does not appear. I can type in a version number while editing, or I can leave the default, {_UIVersionString}, but either way, the entry does not contain the actual SharePoint Version number.

Bryan said...

Mcmerlla, I'm going to add a few screen shots showing my Document Library configuration as well as what I'm seeing in word. Hopefully that will help you out.

Surya said...

How do I display Custom Metadata column value in Word 2003 Document footer automatically while uploading a word file in MOSS Document library?

Bryan said...

Hi Surya,
I have not been able to get this feature to work in Word 2003. I have only been able to confirm this works using Word 2007.

Alan Sutherland said...

Bryan, I hereby declare you a genius.

dadu4net said...
This comment has been removed by the author.
dadu4net said...

Great explain how to add data from SP to Office documents. But when I add version in a WORD document and want to convert the document it gives an error. Have you got an workaround or solution?

Bryan said...

dadu4net, I have not tried converting a MS word document with a SP version number in it to another format, or version of MS word. Feel free to leave a comment with more details about the document conversion trying to do and the error you're seeing. If I have time, I'll try to reproduce it on my end.

Anonymous said...

Are you able to save this site as a template?

I have discovered that (in SP2010) setting up the policy then prevents me from saving the site as a template! (this worked ok for me on 2007)

Any ideas why? Or, more importantly how to get round it?!

Bryan said...

george26 - I just ran a quick test and I was able to save off a site template which contains a document library with an information policy in SP2010. The link to create a site template shows up in the site settings page under the section "Site Actions". If you see the link but the link does not work for your site...then something wacky is going on. Maybe try using the collection administrator account, or another account that has full access to your entire site collection. Hopefully its just a permissions issue, and using an account with higher permission levels will solve the problem for you.

SighLentKnight said...

I also tried to do this on SharePoint 2010, but found that if I save site as template I get "Error exporting list named 'Shared Docuemtns' at the URL: Shared Docuemnts".

I am site collection admiistrator.

If I then disable the Label policy I can save site as template without this error.

I installed SharePoint Server 2010 from MSDN download with Enterprise Cal, in Farm mode on a single server.

Bryan said...

Havent had a chance to try testing on a brand new site yet (I'm still testing off of a site upgraded from MOSS 2007, which may be why it works for me?) ... but have you tried doing a site copy yet? That might get you around the issue if you just need a copy of the site in the same collection.

For sites located at the root of your collection you can create a temporary site off the root, then copy your site into the temporary site, rename it, then copy the copy back to the root. Hopefully that will work.

Anonymous said...

Bryan - yes, this also works for me on a 2007 site migrated to 2010...

SighLentKnight - thanks for repeating the problem - at least I know it's not just me (although I'm sot sure if that's a Good Thing or not?!)

I need to be able to create a site template to give to my customer, so they can create their own project sites. Being able to display the version number in Word Documents is a key requirement for them (and one that works in our 2007 solution) so this not working in 2010 is a real big pain for me.

rick said...

I have tried this and entered everything as per your screen shots except that in the Edit Policy: Document - The preview shows:
Document Version : {Version}
and not
Document Version : {_UIVersionString}
like in your screen shot.
When I follow the steps and place the label in a doc, save and checkin and then checkout again the string does not change. It still shows: Document Version : {Version}
Editing and doing subsequent changes show new versions in Sharepoint but the values are not substituted in the Word 2007 doc.
Is there something in your MOSS 2007 that is turned on/off that maybe we need to do for our site?

Bryan said...

Rick, my first thought - double check that you have versioning enabled on the document library.

A suggestion for troubleshooting - if you happen to be working on a heavily customized document library (custom content types, properties,etc) you might want to try testing this on an out of the box document library first.

Mark B said...

Bryan is my new favorite person! I would bear your children but I'm a guy...

Lael Locher said...

Has anyone had any luck with getting this working with Excel not Word? This solution works perfectly in Word for me but I just see {_UIVersionString} when I follow the process with Excel. I'm running SharePoint 2010 and Excel/Word 2010.

Huet Landry said...

I've run through everything to set up a policy for the specific content type that I am using. The policy appears to be in place, but when I upload a document, the Label does not appear in the Quick Parts|Document Properties list.

Eddie said...

Rick I had the same problem. Instead of {Version}, I typed in {_UIVersionString} directly and it worked.

Chetan said...

Can the Label be formatted? Say if I wanted 3 zeros before the Sharepoint "ID", how would I format the Label?

Unknown said...

Chetan - Check out #5 in the first set of screenshots. You should be able to change the value of the "Label Format" field to have whatever text you want around the version number.

Unknown said...

As a note to others, using Office 2012 it took me several checkin/checkout before the "Label" property became available.

I assume I did something wrong but don't know what. If you have the same problem, trying a couple of checkins/checkouts and see if you get lucky.

PS: Works like a dream Bryan!!

Unknown said...

Hi Bryan,
I have done the settings in My Document Library as per the screenshots which you have added in your Article.
Accordingly i have done the settings in Document Library and now when i upload the document in document library and check out and start editing then under Insert-Quick PArts -Document Property is greyed out/disabled.

But when i directly open any of the Word file in 2010 from my local drive and not the one which is uploaded then the Documet Property is enable from Insert.

Unknown said...

Hi Bryan,
Can you please comment.I need to fix it as early as possible.Yesterday i tried again,but same problem as mentioned in my above comment.

Unknown said...

Hi Gauri,
The issue you are having is tough to troubleshoot. My advice is to create a new, empty team site and try to go through the steps in this post again. See if you can get it working at all in an empty site based on an out of the box site template.

Unknown said...

Hi Bryan,
Thanks for your reply.
Ok i will create a complete new site and check again.

But we need to do this in our existing site which are already uploaded with the documents.

Unknown said...

Hi Bryan,
Please respond ASAP to my comment.As mentioned before,i have followed your steps for settings the library.
But i am facing problem ,when i upload document checked it out and when edit the document then it is giving me message from webpage as :- " The document could not be opened for editing.A Microsoft Sharepoint foundation compatible application could not be found to edit the document".

If i upload the document and open it and start editing then i am not getting the option of"Label" under Document Properties.

Kindly help in this urgently.

Unknown said...

Gauri, check out this KB - - hopefully that will help with the message you're seeing on checkout/edit.

Maybe installing the SharePoint services support component in your version of MS Office will also get version numbers working for you. *Crosses fingers!*

Unknown said...

Hi Bryan,
I will check the link.But what about the "Label" which is not showing inside the Word document under Document Property .?

Unknown said...

Thanks for the link.It worked.
But now new problem.

When i edit the word file from Sharepoint ,insert label then Microsoft word stops working.

do you know why so?

Unknown said...

Hey Gauri, glad to hear the KB helped. Not sure what to tell you about word locking up - maybe do a quick reboot if you haven't tried that already. If you had to install/update office components, a reboot might do the trick.

Unknown said...

Hi Bryan,
Thanks for your quick responses.Yes i have rebooted the machine.But still the same problem.I am facing this problem when i edit the word file and insert the "Label" function.

kirkkeller said...

Hey Bryan,

Great feature. It worked perfectly on our sharepoint and Office 2010. I'm wondering if anyone else has run into this problem, however. Now after the first version is saved, Word flags the version label as invalid. For any doc I create it's the same story. Doc is created, saved to Sharepoint fine, version label works. But edit the doc and Word refuses to save the doc, showing the version label with a red dotted line.

ingeniero22 said...

Thanks it worked perfectly, I'd like to know how to insert it into excel it does not work for me this

Unknown said...

This is a great article for my research. Keep posting. Thank you.


Unknown said...
This comment has been removed by a blog administrator.
Unknown said...

Thanks for the outline. I had this solution working but it seems a recent update has killed it. upon double checking my content type, the label feature was disabled. When I re-enter {Version} and click refresh, I get "The label reference, Version, could not be found". It looks like Microsoft ended support for this feature or something.

I saw another suggestion to use a site column calculated field set =[Version], but the resulting values were incorrect; I get 0s and the numbers don't update. From my readings it looks like there is no way to make that approach work.

I'm at a total loss for how Microsoft could have failed so badly at putting a version number in a document. Help!