2

Is it possible to get only the changes (changed field values) from every version of a List Item in SP 2013? If so, can anyone please explain it in detail with code?

3

There's no direct way provided by the server side API to get version changes. But you can compare the fields of different versions:

using (SPSite site = new SPSite("http://my.domain.com/"))
using (SPWeb web = site.OpenWeb())
{
    SPList list = web.GetList("http://my.domain.com/Lists/Stuff");
    SPListItem item = list.Items[1];

    Console.Out.WriteLine(item.Title);

    SPListItemVersion currentVersion = item.Versions[0];
    SPListItemVersion previousVersion = item.Versions.Count > 1 ? item.Versions[1] : null;

    Console.Out.WriteLine("Version is current: {0}", currentVersion.IsCurrentVersion);

    foreach (SPField field in currentVersion.Fields)
    {
        if (field.ShowInVersionHistory == false)
        {
            continue;
        }

        if (previousVersion == null)
        {
            Console.Out.WriteLine("  > {0} changed to \"{1}\"",
                field.StaticName, currentVersion[field.StaticName]);
            continue;
        }

        if (currentVersion[field.StaticName].Equals(previousVersion[field.StaticName]))
        {
            continue;
        }

        Console.Out.WriteLine("  > {0} changed from \"{1}\" to \"{2}\"",
            field.StaticName, previousVersion[field.StaticName], currentVersion[field.StaticName]);
    }
}

Source

3
  • I am sorry, but I have seen this code and I know this. I was looking for a better solution. – Ven Feb 10 '16 at 9:45
  • I'm afraid a better solution likely doesn't exist. – Submits Feb 10 '16 at 9:57
  • If you are looking for client code, CSOM or Rest API doesn't support this, for no real reason, MS just forgot to implement this. However you should be able to dig out list item versions and values calling old school list.asmx web service. – Diomos Oct 8 '18 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.