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 to share