开发者

SPItemEvent: abort the event from the EventHandler

开发者 https://www.devze.com 2023-02-06 20:04 出处:网络
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开发者_St

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消