We want to prevent users from deleting top level folders in a document library. We created an event receiver on ItemDeleting that checks if the item type is a folder and if the path is the top level, if so it cancels the event.
public override void ItemDeleting(SPItemEventProperties properties)
//Boilerplate code and other logic not shown
errorMsg = "Delete of top level folders is not allowed.";
properties.ErrorMessage = errorMsg;
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.RedirectUrl = "/_layouts/OurCompany/CustomError.aspx?edrmsMsg=" + errorMsg;
This works fine from the GUI however it appears it doesn't work so well from Explorer view. When a user tries to delete a top level folder from Explorer view the event receiver cancels the folder deletion but still allows SharePoint to delete all items inside the folder. We are guessing that SharePoint is not transactional in its deletion of child / nested items.
Is there any way to fix the event receiver to block the deletion of child / nested items, or is there another way to implement our business requirement?