Welcome to MSDN Blogs Sign in | Join | Help

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

Published Friday, January 26, 2007 6:09 PM by Joerg_Sinemus
Filed under: , ,

Comments

# re: WSS version number in the Word 2003 document

Monday, January 29, 2007 8:20 PM by samwise_gamgee

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.

# re: WSS version number in the Word 2003 document

Tuesday, January 30, 2007 2:56 PM by Joerg_Sinemus

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

# re: WSS version number in the Word 2003 document

Wednesday, February 07, 2007 9:46 AM by agoodwin

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)

# Connecting MOSS Version number in Word Documents

Wednesday, February 07, 2007 10:09 AM by in·for·ma·tion /ˌɪnfərˈmeɪʃən/ [in-fer-mey-shuhn]

Finally my first blog post - I've been struggling to find something worthwhile to submit and I suppose...

# re: WSS version number in the Word 2003 document

Friday, February 09, 2007 2:32 PM by Joerg_Sinemus

The SharePoint product group knows this customer need now.

# re: WSS version number in the Word 2003 document

Friday, February 23, 2007 4:47 AM by frommi

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?

# re: WSS version number in the Word 2003 document

Tuesday, February 27, 2007 1:10 PM by Joerg_Sinemus

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

# re: WSS version number in the Word 2003 document

Tuesday, March 13, 2007 11:22 AM by mlh

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

# re: WSS version number in the Word 2003 document

Thursday, March 22, 2007 8:58 AM by bome

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.

# re: WSS version number in the Word 2003 document

Friday, April 06, 2007 8:06 AM by Joerg_Sinemus

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.

# re: WSS version number in the Word 2003 document

Saturday, April 14, 2007 9:56 PM by jloving

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.

# re: WSS version number in the Word 2003 document

Tuesday, June 12, 2007 6:26 AM by Homerhirn

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

# re: WSS version number in the Word 2003 document

Wednesday, June 13, 2007 2:53 AM by Homerhirn

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.

# re: WSS version number in the Word 2003 document

Monday, June 25, 2007 3:50 AM by frommi

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?

# re: WSS version number in the Word 2003 document

Wednesday, June 27, 2007 9:55 AM by Joerg_Sinemus

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.

# Connecting MOSS Version number in Word Documents

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

# re: WSS version number in the Word 2003 document

Monday, December 17, 2007 5:42 PM by boverton

How would I implement to multiple specific  lists?

# "Save Conflict" Error when uploading files

Thursday, March 27, 2008 9:48 AM by Dirk_V

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

Dirk

# re: WSS version number in the Word 2003 document

Thursday, August 07, 2008 1:18 AM by nmanzi

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.

# re: WSS version number in the Word 2003 document

Friday, November 07, 2008 4:20 AM by tomo123

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

# re: WSS version number in the Word 2003 document

Wednesday, January 21, 2009 12:27 PM by dedhandi

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?

Anonymous comments are disabled
 
Page view tracker