How to Retrieve Custom Fields from Older Versions of Items Using the Sitefinity API

Default Blog Top Image
by Atanas Valchev Posted on November 15, 2013
The content you're reading is getting on in years.

This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.

This will be a very short blog post showcasing how to get an older version from the Revision History and then get the value of a custom field. For this example we will use a document.

In order to get the version history of an item, we need to work with the Master version. After we get it, we can use the version manager to get the version history for this item. After that we create a document that will temporarily host the values from the older version we are querying, giving us access to everything we need.

var man = LibrariesManager.GetManager();
var item = man.GetDocuments().Where(d => d.Title=="Blog" && d.Status == ContentLifecycleStatus.Master).FirstOrDefault();
   
 VersionManager versionManager = VersionManager.GetManager();
 var sf_versions = versionManager.GetItemVersionHistory(item.Id);
   
 foreach (var vers in sf_versions)
 {
     var lmdate = vers.LastModified;
     var doc = man.CreateDocument();
     versionManager.GetSpecificVersionByChangeId(doc, vers.Id);
     var cfield = doc.GetValue("CustomField1");
     var title = doc.Title;
 }

Here is a video of the code in action: http://screencast.com/t/p5lSkIBPwhu

Atanas Valchev
Atanas Valchev is a Tech Support Engineer at Telerik. He joined the Sitefinity Support team in March 2012.
More from the author

Related Tags:

Related Products:

Sitefinity

Digital content and experience management suite of intelligent, ROI-driving tools for marketers and an extensible toolset for developers to create engaging, cross-platform digital experiences.

Get started

Related Tags

Prefooter Dots
Subscribe Icon

Latest Stories in Your Inbox

Subscribe to get all the news, info and tutorials you need to build better business apps and sites

Loading animation