Is the Document.AfterNew signature supposed to take an object (CMSNode) and not a Document type as sender? If you cast the object to CMSNode and creates a new Document object from the CMSNode ID you will find that the ContentType property is null.
I would like to add some text to a property for certain Document Types when created, but I can't find any way to do this using the new actionhandlers. I could still use the IActionHandler interface I suppose.. but is this the only way to achieve what I want?
I've actually be doing some tweaks to the New event handlers (did you know there's no BeforeNew event, yet there are two post-new events!) early this evening.
The reason that AfterNew returns you a CMSNode is because it is actually on the CMSNode object, not the Document object (the Document object has a New event though). AfterNew is passed in the CMSNode (which is the base class of Document) but it is actually a bit of a problem, because the CMSNode.MakeNew, which ultimately raises the CMSNode.AfterNew event, is actually fired before the Document is really made. At the point of the CMSNode.AfterNew there has been nothing inserted into the cmsDocument table.
Unfortunately I don't think this is something that will be changed, it's too much of a restructure of the database record insersion. If you want a post-event for Document creation use the Document.New event.
One last note, I'm actually adding a Document.Newing (although I should call it BeforeNew which I hate, it's completely against the rest of the .NET framework event naming conventions :( ) which will allow you to actually cancel document creation! That + the other changes to the Document saving event model I've done means you're going to be able to cancel a document when it's created or when it's saving an existing document (without having the database touched, as I pointed out here: http://www.aaron-powell.com/blog/july-2009/the-great-umbraco-api-misconception.aspx).
Hopefully other people will find the event model useful and I'm not just the only one who's going to use it :P
@slace: others will use it for sure, including me. I'm quite confident this issue has been raised on Codeplex as well, but didn't get the attention it deserves. I've ran into this issue as well, and thought I've voted for it on Codeplex (not sure anymore).
It's great to see you "cleaning" up the stuff, heads up for that, a well deserved vote from me on this forum (apparently, i do get karma points for that as well ;)
Hm, I click the Mark as solved for Slaces post, but it doesn't seem to work. When the page is refreshed the karma is back to "2", and it's not marked any longer.
Document.AfterNew actionhandler
Is the Document.AfterNew signature supposed to take an object (CMSNode) and not a Document type as sender? If you cast the object to CMSNode and creates a new Document object from the CMSNode ID you will find that the ContentType property is null.
I would like to add some text to a property for certain Document Types when created, but I can't find any way to do this using the new actionhandlers. I could still use the IActionHandler interface I suppose.. but is this the only way to achieve what I want?
I thought it would take a Document as a sender not a DocumentType.
Which version of Umbraco are you running? I have read somewhere that there were a few event issues in earlier 4.0.x versions.
The sender is of the type object and can be casted to a CMSNode.
I am using 4.0.2.1
I've actually be doing some tweaks to the New event handlers (did you know there's no BeforeNew event, yet there are two post-new events!) early this evening.
The reason that AfterNew returns you a CMSNode is because it is actually on the CMSNode object, not the Document object (the Document object has a New event though). AfterNew is passed in the CMSNode (which is the base class of Document) but it is actually a bit of a problem, because the CMSNode.MakeNew, which ultimately raises the CMSNode.AfterNew event, is actually fired before the Document is really made. At the point of the CMSNode.AfterNew there has been nothing inserted into the cmsDocument table.
Unfortunately I don't think this is something that will be changed, it's too much of a restructure of the database record insersion. If you want a post-event for Document creation use the Document.New event.
One last note, I'm actually adding a Document.Newing (although I should call it BeforeNew which I hate, it's completely against the rest of the .NET framework event naming conventions :( ) which will allow you to actually cancel document creation! That + the other changes to the Document saving event model I've done means you're going to be able to cancel a document when it's created or when it's saving an existing document (without having the database touched, as I pointed out here: http://www.aaron-powell.com/blog/july-2009/the-great-umbraco-api-misconception.aspx).
Hopefully other people will find the event model useful and I'm not just the only one who's going to use it :P
@slace: others will use it for sure, including me. I'm quite confident this issue has been raised on Codeplex as well, but didn't get the attention it deserves. I've ran into this issue as well, and thought I've voted for it on Codeplex (not sure anymore).
It's great to see you "cleaning" up the stuff, heads up for that, a well deserved vote from me on this forum (apparently, i do get karma points for that as well ;)
@slace: excellent. Somehow I missed the Document.New event. Thanks a lot!
Hm, I click the Mark as solved for Slaces post, but it doesn't seem to work. When the page is refreshed the karma is back to "2", and it's not marked any longer.
It could be to do with the updates the did last night to the forum, try again and if it still fails pop a bug in the bugs forum
is working on a reply...