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