Showing posts with label Event Receiver. Show all posts
Showing posts with label Event Receiver. Show all posts

Thursday, February 23, 2012

Comparing Fields to See if Values Have Changed in the ItemUpdating Method

You cannot get information about what was before the event in the '-ed' EventReceiver, only in the '-ing'.

So, within the public override void ItemUpdating(SPItemEventProperties properties) method...

- The "before" updating value is obtained like this;
var beforeValue = properties.ListItem["Column Name"].ToString();

- The "after" updating value is obtained like this;
var afterValue = properties.AfterProperties[properties.ListItem.Fields["Column Name"].InternalName];

Before making a beforeValue == afterValue comparison you may need to type check these values.