Handling Sharepoint Events .. Which Column Has Changed?

I am writing an event handler to handle updating a specific SPItem in a list. The event is asynchronous and I am getting SPEvenItemProperties without issue. I would like to know which of the SPItems columns actually triggered the event. Does anyone know how to do this?

Thanks in advance.

+2


source to share


2 answers


Your answer depends a little on where and how the SPListItem is restored. In a regular list, you don't have access to the previous values โ€‹โ€‹of the element. If you turn on version control, you can access previous versions, depending on the permissions, of course.

For a document library, you can use 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

+4


source


I think the best way to do this is to look at the BeforeProperties and AfterProperties properties from SPItemEventProperties and check which fields have different values.



They contain the values โ€‹โ€‹of all fields of the element before and after the event.

+3


source







All Articles