Monday, 23 February 2009

Displaying SharePoint version information in Office documents

One thing I get asked for from time to time is to display the latest SharePoint version information in Office documents and templates. I have always found it easier to create new custom columns for this and populate them using an event handler.

Seeing as though I think this may be useful for others, I have uploaded some code and resources to Codeplex which provides this functionality. It comprises of two components:

- A site collection feature to deploy four new custom site columns for use in Content Types or document libraries where version information is to be shown in Office documents.

- A site feature which implements an event handler to populate the custom columns with version information for any document library present in the site, including the current version, when the document was last approved, who approved it, and when it was approved.

Once the custom column information is being populated by the event receiver, it can be shown in Office documents using the Quick Parts (Office 2007) or Fields (Office 2003 or 2007) features.

You can download the solution file, source code, and instructions at http://www.codeplex.com/spversionindocs.

25 comments:

  1. Yes this is a problem we have as well. I've played with the solution and got it to work fine, but it does leave me with one outstanding issue. While Word's properties are updated correctly, where the properties are used in the document as fields are not until you manually refresh the document.

    Age-old Word problem I know, I was just wondering if there was a way to kick an update of the document on the backend?

    Neil.

    ReplyDelete
  2. Hi Neil,

    The only way I have seen this working is by using a macro to refresh the fields on opening the document - this article may help: http://word.tips.net/Pages/T000422_Automatically_Updating_Fields_and_Links.html

    Phil

    ReplyDelete
  3. Hi Phil,

    Yes I'd seem something similar to this before, and have implemented something similar. It is less than ideal though since distributing it is rather difficult. AutoOpen only works in normal.dot or the document itself, not another template you could distribute via login scripts to the startup folder. Got a workaround for that, but still annoying. Oh and if you use Word as your Outlook 2003 compose editor then that stops those macros working.

    You'd think there would be an easier way ;-)

    Neil.

    ReplyDelete
  4. Hello,
    Great solution! I've been looking everywhere for this!! The issue Neil raises is a problematic one (how to get the version number to auto update), but for now I was wondering how to get this to work in Excel?
    There isn't a Quick Parts feature in Excel 2007. Do I have to add macro code to get the version number in the header/footer of an Excel sheet?

    Thanks,
    Aaron

    ReplyDelete
  5. Hi Aaron,

    Glad you liked the solution :) - I personally have not tried adding doc properties to Excel, but typing "document properties excel" into Google gave me quite a few results from people that have, so hopefully there is some info there that may help.

    Regards,
    Phil

    ReplyDelete
  6. Hello Phil,

    If i wanted to make a dutch version of these features. What would i need to change in your code ?

    With regards,

    Hilmar.

    ReplyDelete
    Replies
    1. hello did you manged to build it 4 dutch sites ???

      Delete
  7. Hi Hilmar,

    Just changing any reference to column display names in VersionInfoColumns.xml and ItemEventReceiver.cs should do it.

    For example, look for the DisplayName= values in VersionInfoColumns.xml and make sure the same display names are used for the item["Column Name"] code in ItemEventReceiver.cs. You will also want to change the description field in the xml file as well.

    Phil

    ReplyDelete
  8. Hi Phil

    I installed the solution and the installation process was completed successfully. I also activated the feature inside the site collection but the columns wasn't created.

    please help.

    Best regards
    Chakib

    ReplyDelete
  9. Hi Chakrib,

    A couple of people have reported this on the Codeplex site and it was because they were using WSS and not MOSS (I assume you are doing the same).

    These guys just created the columns manually using the browser interface and it worked fine.

    Phil

    ReplyDelete
  10. Hi Phil!

    Like Hilmar did it (hopefully) for the Dutch Version, I just want to do the same for a German verion.
    To make everything right, how and where (which directory) do I have to change the files: VersionInfoColumns.xml and ItemEventReceiver.cs...
    And where do I find the right column names in German?!

    Thanks for your help!

    Markus

    ReplyDelete
  11. Hi Phil!

    It's me (Markus) again.
    Finally I found the files to change.
    But I've to change "Approval status" to "Genehmigungsstatus" within ItemEventReceiver.cs because of a German version I have here.

    //English Version
    //if (item["Approval Status"].ToString() == "0")
    //German Version
    if (item["Genehmigungsstatus"].ToString() == "0")

    That's no problem either, but: I'm not a developer, so how could I create the new WSP - File with my minor changes?!
    I've looked at the WSP Builder - tool. Could I use this one?!

    Sorry for the real stupid none developer questions. But I hope, there is help available!

    By the way:
    Displaying the "current version" just works as it should!

    Thanks again!

    Markus

    ReplyDelete
  12. Hi Markus,

    I think I used the Visual Studio extensions for WSS to compile this solution - either version 1.2 (http://www.microsoft.com/downloads/details.aspx?familyid=7bf65b28-06e2-4e87-9bad-086e32185e68&displaylang=en) or 1.3 CTP (http://www.microsoft.com/downloads/details.aspx?familyid=FB9D4B85-DA2A-432E-91FB-D505199C49F6&displaylang=en). You would need to install the extensions and then load the solution into Visual Studio. From there you can compile it and it will automatically create the wsp file for you.

    Phil

    ReplyDelete
  13. Hi Phil,

    this looks like a really neat solution - though I cant get it working in my sharepoint environment.

    We have a WSS 3.0 installed, weve run the installation without problem. We have added the columns by adding custom columns.

    The problem is that the columns turns out blank and we are, therefore, unable to show the metadata in the documents as well.

    We have followed the installation pdf and cant figure out what is wrong.

    I seriously hope you can help us since weve been looking for a solution like this one for some three years now.

    Sincerely

    / Daniel Persson

    ReplyDelete
  14. Hi Daniel,

    If the columns are not being populated, it sounds like something is preventing the event receiver from running. Are you sure the SITE feature is enabled in the site containing the document library? It will need to be activated in EVERY SITE you want to use it - unlike the site collection feature which only needs to be activated once during the installation.

    ReplyDelete
  15. Hi Phil,

    I posted this on the CodePlex site: http://spversionindocs.codeplex.com/Thread/View.aspx?ThreadId=232671

    But, since I see very little activity there I decided to post here also. Sorry for the duplication, but I am looking for a solution to the issue if possible.

    First of all EXCELLENT utility. This is a feature that should have been included with SP.

    Installed with MOSS 2007 and clients using both Office 2007 and 2010.

    I have tried using the this both with and without linking to approval workflow. In all instances the "Approved By" field is populated with the the document originator and not the approver. And, not matter the process I use to approve (i.e., work flow or direct approval from dropdown) the result is the same.

    Can someone here give me some direction on how to proceed.


    Thanks in Advance,
    Gus

    ReplyDelete
  16. @Gus - Thanks for reporting the error. This has now been fixed and a new version uploaded on the Codeplex site.

    Phil

    ReplyDelete