Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • anthony hall 222 posts 536 karma points
    Nov 26, 2009 @ 17:09
    anthony hall

    Using Document.BeforeMoveToTrash

    I want to stop users deleting certain doctypes. The below event is called correctly. However

    e.Cancel = true; doesn't seem to cancel the event. Is this is actually cancelling "MoveToTrashEventArgs"

    How do i stop the doc being move to the trash?


            public MoveToTrash()
                Document.BeforeMoveToTrash += new Document.MoveToTrashEventHandler(Document_Trash);

            static void Document_Trash(Document sender, MoveToTrashEventArgs e)
                e.Cancel = true;

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Nov 26, 2009 @ 22:31
    Aaron Powell

    Where are you adding the event handler to the Document class? Chances are it's not wiring up the event

  • soldarnal 4 posts 24 karma points
    May 11, 2010 @ 23:15

    I too am unable to prevent the MoveToTrash event.  I'm adding an event handler for canceling publish in the same place (as shown on umbraco tv), and publish does get canceled.  Does anyone know if MoveToTrash is a cancelable event?

  • Aaron Powell 1708 posts 3046 karma points c-trib
    May 12, 2010 @ 00:43
    Aaron Powell

    Is the event handler being run?

    It is a cancellable event.

  • soldarnal 4 posts 24 karma points
    May 13, 2010 @ 00:52

    I figured out that it is in fact canceling the event.  It just continues to show the animation in the CMS, so it's confusing.  But if you reload the nodes, the one that just dropped off is still there.

  • Stefan Kip 1614 posts 4131 karma points c-trib
    May 13, 2010 @ 01:03
    Stefan Kip

    You could add a bug report to Codeplex here:

  • David Dupont 61 posts 115 karma points
    Oct 29, 2010 @ 17:03
    David Dupont


    It's not only the animation it seems that all children of the node you cancel programmaticaly doesn't appear anymore in the umbraco.config.

    You have to make a publish including all children to get your umbraco.config back to normal. So it really is an issue.
    Before to make a publish I've also tried a "republish entire site" but it doesn't solve the issue. Moreover after having republished, my children have weird "Link to document" and "Alternative Links" (C.f screenshot)

    I'm using a 4.5.1 version, please could you say me if you experiment the same behavior with node children?

    I've added a vote to the issue and added my comments.



  • Markus 33 posts 58 karma points
    Nov 26, 2010 @ 18:16

    And here's the link on codeplex:

  • Kim Løwert 130 posts 116 karma points
    Jan 04, 2011 @ 21:06
    Kim Løwert

    Hi Guys,

    I'm experiencing the same issue. The content node is not moved to the trash, but unfortunately it is deleted from the cache. My solution is the following:

    • Once cancelled republish
    • Then update the document cache to make sure it is republished
    • Save the sort order programmatically without sorting. This will make sure the document in the cache is not moved to the last position of the deleted documents parents children.
    The following is the code I use which seems to solve the issue.

    e.Cancel = true;

    sender.Publish(new User(0));



    if(sender.ParentId > 0)


    XmlNode parentNode = content.Instance.XmlContent.GetElementById(sender.ParentId.ToString());


    //only try to do the content sort if the the parent node is available... 

            if (parentNode != null)

            content.SortNodes(ref parentNode);


            // Load balancing - then refresh entire cache

            if (UmbracoSettings.UseDistributedCalls)



    I hope it will help you guys and solve any issues you may have too.

    Cheers Kim

Please Sign in or register to post replies

Write your reply to: