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

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

Posted on November 15, 2013 0 Comments

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.

Comments

Comments are disabled in preview mode.
Topics

Sitefinity Training and Certification Now Available.

Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.

Learn More
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