Thursday 17 April 2008

How to add the SharePoint versionnumber in your Word 2003 / 2007 document?

You shoud think this is possible out of the box, but no luck ... The SharePoint version field is not exposed in Word 2003 or 2007. The reason is that the version field is not a default text field. So you need to look for a workaround, the most easy way is to create your onw "DocumentVersion" text field and copy the value of the SharePoint version field into the new "DocumentVersion" field with code. You need to execute this piece of code after the document has been added (ItemAdded) or updated (ItemUpdated):

This is a sample:

public override void ItemAdded(SPItemEventProperties properties)
{
SPListItem item = properties.ListItem;
item["NameOfYourNewField"] = item["Version"];
item.SystemUpdate(false);
}

Here you can find the full blogpost about adding the version field in Word 2003:
http://www.sharepointblogs.com/johnwpowell/archive/2007/07/13/display-version-number-and-other-sharepoint-metadata-in-word-2003-documents.aspx

If you want to know how to add the field in Word 2007, check here:
http://office.microsoft.com/en-us/word/HA101004261033.aspx?pid=CH100992711033#2