WSS version number in the Word 2003 document


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:

<?xml version="1.0" encoding="ISO-8859-1" ?>

<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>


    <Receiver>


      <Name>ItemAdded</Name>


      <Type>ItemAdded</Type>


      <SequenceNumber>10010</SequenceNumber>


      <Assembly>FeatureTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=36d210293b917bd0</Assembly>


      <Class>test.TestEventReceiver</Class>


      <Data />


      <Filter />


    </Receiver>


  </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)


        {


            DisableEventFiring(); // in ValidateItem it will fire an event, so disable here


            ValidateItem(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 2007
SDK for Windows SharePoint Services V3
Document Property Promotion and Demotion
Introduction to Columns
Event Fundamentals

Comments (28)

  1. samwise_gamgee says:

    Hi there,

    Thank you for the helpful post. However — I am wondering if you (or anyone else out there) could help me

    with an issue I’ve been having lately with WSS 3.0.  Here’s a summary of my environment:

    DEV ENVIRONMENT SUMMARY:

    ===================================================

    "bare" WSS 3.0 RTM (RTW) running on W2k3 SP1

    MOSS (ie. SPS) 2007 is NOT installed.

    MAIN GOAL:  Leverage WSS 3.0’s versioning functionality for network communications management application.

    Installation of Event handlers is via Object model, NOT by features.

    PROBLEM SUMMARY:

    ===================================================

    I have written classes to override the "ItemUpdated", and "ItemAdded" methods as shown in this article, as

    well as trying to tap into other methods such as "ItemCheckedIn" "ItemDeleted" etc.  I have successfully been

    able to get the events to fire for simple tests.

    Now, as I prepare to deploy my event handlers in a more commercial environment, I have been running

    more rigorous tests, and have been getting very inconsistent behaviour with respect to the events

    firing on document libraries:

    The following WORKS:

    — a) If I trigger events via the SP Web UI

    — b) If I "SLOWLY" trigger events via the SP Object Model (ie. using SPFolder.Add(..) and SPFolder.Delete(..) methods)

       By "SLOWLY" I mean that I artifically "sleep" for a few seconds between consecutive calls.

    The following DOES NOT WORK (or works at best very inconsistently)

    — c) If I "QUICKLY" trigger events via the SP Object Model (ie. using SPFolder.Add(..) and SPFolder.Delete(..))

       By "QUICKY" I mean that I remove all of my artificial sleeps and let the code in b) run normally.

    The events sometime fire, sometimes not.  On a document library of ten items, I may have ZERO events fire, or

    I may get the events to fire only on the 1st, 3rd, and 8th item for example.  It is, as far as I can tell,

    rather random.

    Has anyone else noticed such strange behaviour?  I have searched and every example

    I’ve come across usually focuses on very simple docLib events (triggered via the SP UI), and often do not

    consider what would happen if MANY MANY events happen at once.  

    Though I feel the doclib events ins WSS 3.0 /SPS 2007 are a great enhancement from WSS 2.0

    — I am apprehensive to fully commit if the event model doesn’t stand up well under high event loads?

    Thanks in advance for any help you can provide.

  2. The best way to get and give community support could be one of our newsgroup. Start here http://www.microsoft.com/technet/community/newsgroups/server/sharepoint.mspx

  3. agoodwin says:

    Great post and this is exactly what I have been trying to achieve!

    My big questions is: why the hell wasn’t this feature included in the WSS/Word integration options by default??!!! After all, once a document is in library you can connect any custom metadata using the Quick Parts as well as some defaults. So why not Version?? it’s one of those items often used in word headers.

    Serious lack of forsight on the part of the MOSS development team? or just too complicated to get into this release?(doubtful)

  4. Finally my first blog post – I’ve been struggling to find something worthwhile to submit and I suppose…

  5. The SharePoint product group knows this customer need now.

  6. frommi says:

    I’m curious as to how steps 4 and 5 need to be performed.

    [On a remote machine] I did create a .cs file with the code above and "compiled" it to a DLL using csc.exe. I copied the DLL to the Sharepoint server but gacutil wouldn’t add it to the GAC, stating an "unknown error".

    Are there any further steps need to be taken or did I miss something essential? Is there a little more step-by-step guiding howto on these to steps (compiling and adding to the gac) for this?

  7. I created the DLL directly on the SharePoint Server due to some relationships (Use solutions in VS2005, *.SLN). The DLL should be in the GAC and not somewhere else.

    For those questions like “how to” please refer to the MSDN and community support.

    How to: Create a Simple Feature

    http://msdn2.microsoft.com/en-us/library/ms475286.aspx

    How to: Create an Event Handler Feature

    http://msdn2.microsoft.com/en-us/library/ms453149.aspx

    Last but not least refer also to the Visual Studio 2005 help/support/community.

    Community support:

    http://www.microsoft.com/technet/community/newsgroups/server/sharepoint.mspx

  8. marclhost@hotmail.com says:

    Thanks very much for that post.

    Is that feature required because of office 2003 usage or it is required too with office 2007 ?

    Many thanks for the answer

  9. bome says:

    The easiest way is to create a new column called WSSVersion in the document library. Set it up as a calculated column and add [Version] as formula. No coding needed.

  10. The feature should work DOC’s and is not fully tested to work with fully featured DOCX’s.

    The reason for the feature is because the calculated column works one time.

  11. jloving says:

    I am also trying to use the [Version] field.  How can I use feature to create a customized starting value for [Version]?  This seems to be the closest I have come to finding an answer. Online for days with no such luck.  Thank you in advance for any help you may provide.

  12. Homerhirn says:

    Hi

    Hopefully someone still watches at this post.

    We need this feature ’cause we want to use MOSS to control our Doc-Version. I (hopefully) successfully implemented all the steps above, created the XMLs, the DLL, signed it on the Server and put it in the GAC and activated the feature (Took me a lot of time, cause I’m doing this the first time ever). First I made some mistakes, but I think I cleared them all out, but the feature still won’t work (Already uninstalled the old versions and reinstalled the error-free-version).

    I put a Field-Control in my template word document, name it "WSSVersion" and assign a value of 0.1 but when the version in the WSS-library is changed, the "0.1" in the document stays and won’t update to the newer version number.

    My Suspection is, that it has something to do with the elements.xml Do I have to change the following line from the example above with my Template-Owner GUID and ID or can I leave it just like in the example?

    <Receivers ListTemplateOwner="00BFEA71-E717-4E80-AA17-D0C71B360101" ListTemplateId="101">

    If I have to change it, how can I find out my GUID and ID?

    I would be very reliefed, if someone can help me. I put a lot of time into this, and I’m starting to going crazy 😉

  13. Homerhirn says:

    Hi there!

    Never mind, I got it! Although in my eyes there is missing something very important in the article above: to create a column named "WSSVersion" in the doclib!

    Correct me if I’m wrong, but this was the magic missing step.

  14. frommi says:

    This works great with my Microsoft Office Word files, thanks!

    I wonder whether this is also possible with Visio *.vsd files and Excel XLS files.

    With Visio I cannot add the WSSVersion property – it’s simply not available for selection. Is there a workaround?

  15. It’s good to know that this works for you in WinWord.

    For any other Office document, XLS, VSD,… it could be straight forward. The properties we are talking about here are also available by the Explorer, the operating system explorer. That means navigate to the folder where the file exists and right-mouse-click properties. Here you can see/edit/add for a lot of known Office files the custom properties.

    Sample:

    – Create Word (DOC), Excel (XLS) and Viso (VSD) file, save it into a doclib where the column WSSVersion exists.

    – Double check that the WSSVersion column has a value for all three documents

    – Download the three files to your Desktop

    – Check each file with right-mouse-click properties

    You should see in all these three documents that there is a new property called WSSVersion and the value should be also there.

    The next step will be how to get this value of the file-property WSSVersion into the sheet, drawing page… For that task please check with specialists in the particular area. With a briefly look it seems that you need VBA code for Excel and Visio.

  16. This one has been resurrected from the collection of post-crash blogs: How is it possible to connect

  17. boverton says:

    How would I implement to multiple specific  lists?

  18. Dirk_V says:

    The suggested solution triggers a "Save Conflict" Error when attempting to upload files. Any suggestions how to remediate this problem?

    Dirk

  19. nmanzi says:

    I have developed a small sharepoint feature that will do this for 5 previous versions so the details can be put into a table inside the document.

    http://nathanmanzi.com/?p=12

    You’ll need to compile it yourself and do some prep work to make it work though. A macro can be used to automatically update document fields whenever the document is opened.

  20. tomo123 says:

    Here is a simple method of posting the version number into a word 2007 document using labels…

    1. Create a document library and enable versioning (Either major or minor) and content types.

    2. Add any new metadata fields to the library as required.

    3. Add your content types.

    4. Go into document library settings and select the first of your content types.

    5. Select Information management policies settings from the content type menu.

    6. Select define a policy and click ok.

    7. Click on the ‘Enable Label’ Check box

    8. DO NOT Check the other two boxes in the Labels section.

    9. In the Lable Format field, enter the metadata fields in the following format…

    Reference : {Reference} n Version : {Version} n Classification : {Classification} n Custodian : {Custodian}

    10. Set the label appearence and click on preview.

    11. Click ok at the bottom of the page.

    The next steps relate to Word 2007….

    12. Go back to the library and create a new document using the content type you have modifed. The document should open in word

    13. IMPORTANT : Save the file as a Word 2007 format now.

    14. Select the insert tab

    15. Select Quick Parts from the Ribbon menu and hover over document property

    16. Select Label from the properties list

    17. This should display the metadata defined in your label as a field in your word document. The field will update automatically when you next open the document.

    18. Don’t forget to save!

    Finished

  21. dedhandi says:

    My company is fairly new to WSS and we’re just learning what it can do. We’re also struggling towards ISO 9001:2008 accreditation and document versioning is an important factor. The problem is we don’t have the programming knowhow or the time to implement our own solution or one that is too code heavy. I really like Bome’s solution and got this to work partially (in that the bit in sharepoint worked). The problem comes when trying to insert the property in a Word document, where it doesn’t exist. Is there a way to add it as a field code?

  22. MisterDee says:

    I seem to have got this working for me.

    I’m not a SharePoint expert by any means but have had this dumped on me at work.

    I needed a solution which works with Word 2003 and requires no coding except for creating a small refresh macro in Word.

    Basically, I found that if you

    1. Turn on versioning

    2. Create a ‘Document’ Content type, set its group as ‘Policy’

    3. Upload your word document to SharePoint as a Content type

    4. Add the Content type to your library

    5. Define a Policy for your Content type and enable labels

    6. Create a new Word document in SharePoint from that Content type

    7. Edit the Word document and add the field “DLCPolicyLabelValue” created by SharePoint as a property for your document

    8. Add a macro to the Word document so it refreshes the document version set by SharePoint every time you open it

    9. Upload this as your new document template

    Every time you create a new document from within SharePoint and save new versions etc. it updates the document version number within the Word document.

    I’ve done a step by step guide of what I did in order to get it working if you need it. It assumes that you have admin access to your SharePoint site. There are also settings which you may want to skip, sorry about this but I didn’t want to leave anything out.

    In SharePoint

    1) Turn on Versioning:

    Go to your Document Library

    Settings > Document Library Settings > Versioning Settings

    Require Content Approval for Submitting Items: Yes

    Select: Create major and minor (draft) versions  

    Select: Only users who can approve items (and the author of the item)

    Select: Require documents to be checked out before they can be edited?

    Click OK

    2) Set up a New Content Type:

    Site Actions > Site Settings > Site Content Type Gallery > New Site Content Type

    Name: Operating Procedure

    Description: Template for new operating procedure

    Select parent content type from: Document Content Types

    Parent Content Type: Document

    Existing group: Policies

    Click OK

    Outside of SharePoint:

    3) Create a blank Word 2003 document:

    Save it somewhere you can find it later, let’s call it "Operating Procedure.doc"

    In SharePoint, upload your blank Word document:

    Site Settings > Site Content Type Gallery > Site Content Type > Advanced Settings

    Upload a new document template: browse for Operating Procedure.doc

    Should this content type be read only: No

    Update all content types inheriting from this type: Yes

    Click OK

    4) Add your word document content type to your library:

    Go to your Document Library

    Settings > Document Library Settings > Add from existing site content types

    In Available Site Content Types: select Operating Procedure and click Add

    Click OK

    5) Create a policy for your Content Type:

    Scroll down to Content Types and click: Operating Procedure

    Under Settings, Click: Information management policy settings

    Specify the Policy: Define a policy > Click OK

    Administrative Description: Operating Procedure Type

    Policy Statement: This is a policy statement

    Click tick box: Enable Labels

    Label Format: Document Version: {Version}

    Font: Arial

    Size: 10

    Style: Bold

    Justification: Center

    Label Size:

    Height: 0.5

    Width: 5.0

    Click ‘Refresh’ button under preview

    This should display Document Version:  {_UIVersionString}

    Click Enable Auditing and tick all 5: Specify the events to audit

    Click OK

    6) Create a new Word document within SharePoint:

    Go to your document library

    Click New > Operating Procedure

    This should open a blank word document

    Save it as "Test Operating Document.doc"

    Click OK

    Close Word

    In SharePoint you should have a document to check in, check it in and select:

    What Kind of version would you like to check in: 0.1 Minor Version (Draft)

    Keep the document checked out after checking in this version? No

    Click OK

    7) Edit the document and add the Document Version field:

    Go to you Document Library and select the drop down next to Test Operating Document

    Select “Edit in Microsoft Word”

    In Word

    Go to: Insert > Field

    Categories: (All)

    Field Names: Doc Properties

    Field Properties: DLCPolicyLabelValue

    Click OK

    "Document Version: 0.1" should appear

    8) Create a macro to refresh the document version field every time it is opened:

    Go to Tools > Macros > Macros…

    Macro Name: AutoOpen

    Click Create

    Paste this:

       With Options

           .UpdateFieldsAtPrint = True

           .UpdateLinksAtPrint = True

       End With

       ActiveDocument.Fields.Update

    Close the VB Editor

    Save this document over Operating Procedure.doc that you saved somewhere at the beginning of this process

    Close Word

    9) This is now your new template for this Content type:

    In SharePoint

    Go to your Document Library

    Settings > Document Library Settings

    Click Operating Procedure

    Click Advanced Settings

    Upload a new document template: browse for Operating Procedure.doc that you have just resaved

    Click OK

    Hope this helps…

  23. MisterDee says:

    Forgot to add – We are using MOSS 2007 (not enterprise I think??) and Office 2003

  24. J. Salazar says:

    Hi, thanks for that!

    I am currently using this solution and I find it very useful. I am using files Word 2003 and 2007, Excel 2003, PowerPoint 2003. And I have created several columns with additional information to the version. But I’m trying to use with Project (.mpp) and AutoCAD (.dwg), but not work.

    Know any way to make it work with these files?

    Thanks again!

  25. It's nice to see that this blog post is still a reference to have the version number available inside a document stored in a DocLib. That sounds to me as a good idea to create an update also in regards of our new SharePoint 2010 products.

    Short info when asking about other file types.

    – First Step:

    "Copy" the SharePoint internal version number into a DocLib Column.

    – Second Step:

    Think about promotion and demotion how SharePoint is able to put the Metadata (the columns) into a file.

    How the second step works in WSSV3/MOSS2007 ?

    ———————————————————————

    SharePoint uses Promotion and Demotion to “exchange” property/column values from/to documents. To fulfill the needs we will talk about Document Parsers. For MOSS 2007 and WSS V3 the best documentation you can find here:

    What does it mean Document Property Promotion and Demotion?

    msdn.microsoft.com/…/aa543341.aspx

    Document Parsers in SharePoint (1 of 4): Overview / WSS V3

    blogs.msdn.com/…/sharepointbeta2documentparseroverview1.aspx

    Here we have the most important words that build in parsers are not changeable.

    WSS includes built-in document parsers for the following file types:

    •         OLE: includes DOC, XLS, PPT, MSG, and PUB file formats

    •         Office 2007 XML formats: includes DOCX, DOCM, PPTX, PPTM, XLSX and XLSM file formats

    •         XML

    •         HTM: includes HTM, HTML, MHT, MHTM, and ASPX file formats

    How about SharePoint 2010?

    —————————————-

    In the new version of SharePoint Foundation 2010 and also Microsoft SharePoint Server 2010 it should be possible to write an own parser also for the build-in file types.

    SharePoint Document Management SPF2010

    msdn.microsoft.com/…/ms431814.aspx

    Custom Document Parsers SPF 2010

    msdn.microsoft.com/…/aa544149.aspx

    This might be the solution with our new SharePoint Foundation 2010.

    Caution

    SharePoint Foundation 2010 includes a number of built-in document parsers. You can replace a built-in document parser with a custom parser, but you should do so only after careful consideration, particularly if you are thinking of replacing a parser for an HTML-based file type. The built-in parsers sometimes do more than the pluggable parser interface allows.

    #######################

    Summary for the Second Step:

    You need an own Document Parser to also have Metadata "published" into your MPP and DWG files.

  26. Dee says:

    Thanks for help with getting the version to show in Word 2003 – the step by step guide was great help! Can anyone help me get the Sharepoint 2007 version number to populate and update in Excel 2003.

  27. Do it for Excel in the same way. You might need a formula in a cell to show the DOC-Property value.

  28. Urs says:

    We are running a WSS 3.0 and we are not experienced in C#-programming… but we realy need this function to print the "WSSVersion" in our «Quality System Documents». Would it be possible to get the dll as a download?

    Hope, someone will have a heart…

Skip to main content