We have now the third version of Team Services and it is called Windows SharePoint Services V3. It is now possible to have a better handling of version controlling means Major and Minor versions in a document library. Why not have this information also in the document and be able to print it out?
The property differences:
Here we see the standard property window and please refer to the Revision number. This number you could call Version but it is only an internal number which is 8 bit long and not accessible from outside. This means we have to find a different way.
We have to use custom properties. If you open an existing word document in a doclib you will see the property ContentType. Why not put also the version number in a similar property?
The goal:
We start with a new document by a click on New in the doclib. I changed the template.doc to have my property “WSSVersion” configured with the first value “0.1”. To see a value of DocProperty you must insert a “Field” and choose the appropriate property. These fields must also be recalculated to show the right value! The standard is that those fields are recalculated when you print the document.
The next deal is how to put the right value at the right time into this property or also called doclib-column?
Feature?
We will use a new feature comes with WSS V3 and .Net Framework 2.0 and it is also called feature in WSS.
Refer to the path on your server: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES and you will see a lot of other folders.
At this place we can also install our “Version Feature”. For this sample I am using the folder C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\DocVersion
1. We need a feature.xml in folder DocVersion:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<Feature Scope="Web"
Title="Get the version into the document"
Description="Have also the SharePoint version number of a document into the document."
Id="00000000-0000-0000-0000-000000000000"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="elements.xml" />
</ElementManifests>
</Feature>
For the "00000000-0000-0000-0000-000000000000" you need your own GUID and create it by GUIDGEN
2. We need an elements.xml in folder DocVersion:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers ListTemplateOwner="00BFEA71-E717-4E80-AA17-D0C71B360101" ListTemplateId="101">
<Receiver>
<Name>ItemUpdated</Name>
<Type>ItemUpdated</Type>
<SequenceNumber>10010</SequenceNumber>
<Assembly>FeatureTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=36d210293b917bd0</Assembly>
<Class>test.TestEventReceiver</Class>
<Data />
<Filter />
</Receiver>
<Name>ItemAdded</Name>
<Type>ItemAdded</Type>
</Receivers>
</Elements>
3. We need the code for this feature and here with C#. In this case name the DLL you will create FeatureTest.dll in Visual Studio 2005SP1:
using Microsoft.SharePoint;
using System;
namespace test
{
class TestEventReceiver : SPItemEventReceiver
public override void ItemUpdated(SPItemEventProperties properties)
DisableEventFiring(); // in ValidateItem it will fire an event, so disable here
ValidateItem(properties);
}
public override void ItemAdded(SPItemEventProperties properties)
protected bool ValidateItem(SPItemEventProperties properties)
SPSite siteV = null;
SPWeb webV = null;
if (properties.ListItemId > 0 && properties.ListId != Guid.Empty)
try
siteV = new SPSite(properties.WebUrl);
webV = siteV.OpenWeb();
SPList spList = webV.Lists.GetList(properties.ListId, false);
SPListItem Item = spList.GetItemById(properties.ListItemId);
// The internal number ist stored in _UIVersion
// 1 for V0.1
// 512 for V1.0
// 513 for V1.1
// 1024 for V2.0
//Item["WSSVNumber"] = Item["_UIVersion"];
// I'm using the string value
Item["WSSVersion"] = Item["_UIVersionString"];
Item.SystemUpdate();
catch // You will run into an exception in case the Column does not exist
// Put your exception code here
return true;
4. Compile your DLL
5. Put the DLL into the GAC by GACUTIL
6. Install the feature by STSADM -o installfeature -filename DocVersion\feature.xml
7. Activate the feature by the GUI or with STSADM
8. Try it out how it works
Reference section:SDK for Microsoft Office SharePoint Server 2007SDK for Windows SharePoint Services V3Document Property Promotion and DemotionIntroduction to ColumnsEvent Fundamentals