Friday, April 27, 2012

Getting field value for specific item version

In this blog entry I will share some findings regarding SharePoint API for items versioning in document library.

SPListItem object contains two properties which can be used to access valuable information about item versions: In my case it turns out that Versions property of SPListItem object is a perfect choice. It contains two useful methods GetVersionFromLabel and GetVersionFromID which allows you to get specified version of list item. In my case I used GetVersionFromLabel. Then it is enough to get value of field using indexer on returned SPListItemVersion object with field name. Below very simple code snippet for reference.
var documentLibrary = site.Lists["mylibrary"] as SPDocumentLibrary;
var listItemVersions = list.GetItemById(1);
var listItemVersion = listItemVersions.GetVersionFromLabel("2.0");
var title = listItemVersion["Title].toString();
Again, simple and easy.

No comments:

Post a Comment