.NET, SharePoint, Technical

Document Version Properties

I’m currently working on a SharePoint project involving a requirement to embed the current version into each document.  Not an uncommon requirement, but at the end of the day it required an uncommon solution due to various issues I hope to post about.  Along the way I found myself needing to access the AfterProperties in an event receiver in order to read the current version of the document.  I knew the version info was in there somewhere, but I didn’t know which exact property I needed.  To figure out my possibilities, I added the below code to my event and ran through it with the debugger seeing what was there:

//Loop through all
properties to see what’s available

foreach
(DictionaryEntry prop1 in properties.AfterProperties)

{

    string key = prop1.Key.ToString();

    string value = prop1.Value.ToString();

}

 

The two properties that looked good were vti_docstoreversion and vti_sourcecontrolversion.

 

After some investigating using the debugger and some different test cases I determined that vti_sourcecontrolversion was the one I needed.  

 

The vti_docstoreversion stores an integer that represents how many times the document has changed.  The vti_sourcecontrolversion stores the version you see in the UI, such as “2.1”.   As an example, with major and minor versioning enabled for a library, add a document.  Without publishing, it’s displayed version will be .1.  Make an edit and it will be .2.  Publish a major version and the displayed version will be 1.0.  In this example, the docstoreversion value will be 3 and the sourcecontrolversion value will be 1.0.

 

I hope that helps someone as I didn’t find this documented anywhere online.

0 thoughts on “Document Version Properties

  1. Wow, this is really goofy the way sharepoint stores versions.

    When I upload a document for the first time what is the vti_sourcecontrolversion versus the vti_docstoreversion?

    Then the document has changed and I upload the document again. What is the vti_sourcecontrolversion versus the vti_docstoreversion?

    Then, finally, the document has changed and I upload the document again. What is the vti_sourcecontrolversion versus the vti_docstoreversion?

    To me the the vti_sourcecontrolversion is 3, and the vti_docstoreversion is 3.

    Is this correct?

    Thank you and Regards,
    John

    1. That’s a small variation on the example I gave. docstoreversion will be 3. The value of sourcecontrolversion will either be .3 if you didn’t publish a major version, or 1.0 if you publish a major version as your final step.

Leave a Reply

Your email address will not be published. Required fields are marked *