Prevent the User from Deleting SharePoint List Item with Notification

Below are the Item Deleting event receiver code  which prevents user from deleting an item with the notification.

/// <summary>
/// An item is being deleted.
/// </summary>
public override void ItemDeleting(SPItemEventProperties properties)
{
    base.ItemDeleting(properties);
    properties.Status = SPEventReceiverStatus.CancelWithError;
    properties.ErrorMessage = "This item cannot be deleted, Please Check your admin Team";
    properties.Cancel = true;
}
 
If you remove the line "properties.Error Message = "This item cannot be deleted, Please Check your admin Team"; the code still works but there wont be any notification provided to the user.!!
Ebook Download
View all
Learn
View all