I have created an event receiver to evaluate the value of a person field when the item is being updated and execute some code if it has been updated. The code is pretty simple and looks like this:
public override void ItemUpdating(SPItemEventProperties properties)
{
base.ItemUpdating(properties);
// Check if person field has been modified
string currentValue = properties.ListItem["AssignedPerson"].ToString();
string newValue = properties.AfterProperties["AssignedPerson"].ToString();
if (currentValue != newValue)
{
// do something
}
}
The receiver works fine if both current and new values are not blank, but if either is blank I'm getting a NullReferenceException
.
Is there a proper way to check for blank person field values or should I just handle blank values before setting the string variables?