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.
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.
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.
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
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
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!
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():
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
is working on a reply...