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.
Here is a video of the code in action: http://screencast.com/t/p5lSkIBPwhu
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.