0
votes

Lets suppose I have an Item with 5 versions. (I am not talking about language versions).

I would like to compare all the versions to identify the differencies. Is there some thing available out of box from Sitecore to do this task? Or I have have to loop over all the versions and then all the fields to find the differences.

1
Do not understand the question, You can use the version compair function in Sitecore, and select to different version of an item to compair. why loop over all versions? - Jan Bluemink
Are you talking about this Sitecore version compare. I want to show info to normal users who are not content editors. - Kamran
Yes, but I understand now that you want something for website visitors? so programtically, I don't think it is in Sitecore - Jan Bluemink

1 Answers

1
votes

No, there is nothing like that out of the box. You will have to compare fields one by one.

Remember that some of the fields should be ignored (like __Updated, __ValidFrom, __Workflow State, etc).

Remember that it's not easy to display what was changed in Blob fields.

And here is a code for you to start with:

FieldCollection fields = version1.Fields;
fields.ReadAll();
fields.Sort();
foreach (Field field1 in fields)
{
    if (field1.ShouldBeTranslated)
    {
        Field field2 = version2.Fields[field1.ID];
        var value1 = field1.Value;
        var value2 = field2.Value;
        ... // whatever you need here

Make sure you add all the necessary null checks! I skipped them for the clarity.