Prevent content with child nodes from being deleted in umbraco

Posted by Soldarnal on Stack Overflow See other posts from Stack Overflow or by Soldarnal
Published on 2010-05-07T21:02:43Z Indexed on 2010/05/07 21:18 UTC
Read the original article Hit count: 218

Filed under:

I would like to prevent content nodes from being trashed if they have any children. I setup an event handler like so:

public class KeepSafeEvents : ApplicationBase
{
    public KeepSafeEvents()
    {
        Document.BeforeMoveToTrash += new Document.MoveToTrashEventHandler(Document_BeforeMoveToTrash);
    }

    void Document_BeforeMoveToTrash(Document sender, umbraco.cms.businesslogic.MoveToTrashEventArgs e)
    {
        if (sender.HasChildren)
        {
            e.Cancel = true;
        }
    }
}

However, this doesn't seem to work. I assume it is because the delete process moves the child nodes to trash first before dealing with the parent node (which then has no children). Is there another possible solution? Or am I making a simple mistake above?

© Stack Overflow or respective owner

Related posts about umbraco