R – Sharepoint event handling.. which column changed

event handlingsharepoint

I'm writing an event handler to handle the updating of a particular SPItem in a list. The event is asynchronous and I get the SPEvenItemProperties without a problem. What I would like to find out is which of the SPItems columns' actually fired the event. Anyone have any idea how?

Thanks in advance.

Best Answer

Your answer depends a bit on from where and how the SPListItem is retrieved. In a regular list, you do not have access to the previous values of the item. If you turn on versioning, you can get access to the previous versions, depending on permissions, of course.

For a document library you can use the SPItemEventProperties.BeforeProperties to get the previous metadata for a document.

For a document library you can try something like this:

foreach (DictionaryEntry key in properties.BeforeProperties)
{
    string beforeKey = (string)key.Key;
    string beforeValue = key.Value.ToString();

    string afterValue = "";
    if (properties.AfterProperties[beforeKey] != null)
    {
        afterValue = properties.AfterProperties[beforeKey].ToString();
        if (afterValue != beforeValue)
        {
            // Changed...
        }
    }
}

.b