Copied to clipboard

Flag this post as spam?

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


  • Lennart Stoop 304 posts 841 karma points
    Jan 18, 2012 @ 12:16
    Lennart Stoop
    0

    Using Document.MakeNew does not fire Document_New event

    Hey guys,

    I would like to create some documents programmatically using the Document.MakeNew() method. After publishing them I would like them to be organized in date folders (for which I'm using kipusoep's awesome date folder package - http://our.umbraco.org/projects/developer-tools/datefolders).

    When I call the Document.Publish() method in code it seems like the events which do the sorting aren't fired however (added in the date folder package as Document_New, Document_AfterSave).

    Am I missing something, do I need something else to trigger these events?

    I have also tried Document.SendToPublication() but that doesn't fire the events either.

     

    Grtz

    L

     

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Jan 18, 2012 @ 12:39
    Jeroen Breuer
    1

    Maybe you should have a look at the source of the Document object. There you can see which events are fired at what moment: http://umbraco.codeplex.com/SourceControl/changeset/view/751c9aa11bbd#umbraco%2fcms%2fbusinesslogic%2fweb%2fDocument.cs.

    Jeroen

  • Lennart Stoop 304 posts 841 karma points
    Jan 18, 2012 @ 13:03
    Lennart Stoop
    0

    Obviously the Document.Newing event won't ever work as the property (date) I wish to organize the folders for is yet to be set.

    For the Document_AfterSave() method to be fired, I just need to call Document.Save() method as well (which kinda makes sense :p)

    Thanks for pointing me in the right direction, Jeroen!

  • Daniel.S 50 posts 135 karma points
    Jan 25, 2012 @ 03:14
    Daniel.S
    0

    Document.Save() gets called as part of Document.MakeNew() anyway. This caught me out with event handlers looking for values that obviously hadn't yet been set on a newly-created document.

    At the very end of Document.MakeNew():

           // Save doc
                d.Save();
    
                return d;
            }
  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Jan 25, 2012 @ 06:52
    Jeroen Breuer
    0

    Yes .Save() is called at many places. You have to watch out not to do this yourself in some events. For example if you call sender.Save() in the before_save or after_save event this will cause an endloos loop and you have to be careful with those :p.

    Jeroen

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies