If you want to get value from a field in ItemDeleting event, you will need to call SPEventProperties.ListItem[“FIELD_NAME”].ToString() method. If you try to get a field value using AfterProperties or BeforeProperties properties, you will get System.NullReferenceException. The reason is these properties are only accessible in ItemUpdating or ItemUpdated events. An example of ItemDeleting event receiver is provider below:
try
{
string fieldValue = "";
fieldValue = properties.ListItem["FIELD_ID"].ToString();
}
catch (Exception ex)
{
properties.Cancel = true;
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.ErrorMessage = ex.ToString();
}
0 comments:
Post a Comment