SPItemEvent: abort the event from the EventHandler
How can I abort an item even (in my case, ItemDeleting) so that it doesn'r get executed? I want the deletion not to take place if certain conditions are matched and do it silently for the us开发者_StackOverflow社区e (no messages, no exceptions). Thanks
EDIT: SP 2010
public override void ItemDeleting(SPItemEventProperties properties) {
properties.Cancel = true;
properties.ErrorMessage = "Something went wrong!";
}
If you cancel it though, it will be reported back to the user, nothing you can do about that.
UPDATE
For use the Status property
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.speventpropertiesbase.status.aspx
public override void ItemDeleting(SPItemEventProperties properties) {
properties.Status = SPEventReceiverStatus.CancelNoError;
}
精彩评论