On my site I register events - that means I create nodes. Some of the data entered, when creating an event, I want to have stored in tables I have made.
So my question is: how can I get my code called when the node is saved?
you should be able to do this quite easily by extending ApplictionBase. Here's a quick example:
using System; using System.Text; using umbraco.BusinessLogic; using umbraco.cms.businesslogic.web; using umbraco.presentation.nodeFactory; using umbraco.cms.businesslogic; using umbraco.cms.businesslogic.media; using System.Web;
namespace MyNamespace { public class MyClass : ApplicationBase { StringBuilder _sb = new StringBuilder(); Utilities _u = new Utilities();
// default constructor; call the event public MyClass() { Document.AfterPublish += new Document.PublishEventHandler(Document_AfterPublish); }
//Check if the doctype is news if (sender.ContentType.Alias == "MyNodeType") { // Just hit my node type so let's log that we did Log.Add(LogTypes.Custom, sender.Id, "In my node type");
// access document type props sender.getProperty("MyDocTypeProperty");
// execute custom code...
Log.Add(LogTypes.Custom, sender.Id, "Success writing stuff to my custom DB"); } } } }
The most important thing to remeber is that your class is public. Then, all you need to do is drop your assembly in the /bin folder and Umbraco will pick it up.
Calling own code when a node is created
On my site I register events - that means I create nodes. Some of the data entered, when creating an event, I want to have stored in tables I have made.
So my question is: how can I get my code called when the node is saved?
Thanks Paul S
Hi Paul,
Check out ApplicationBase for registering event.
http://our.umbraco.org/wiki/reference/api-cheatsheet/using-applicationbase-to-register-events
Regards,
Anders
Hi Paul,
you should be able to do this quite easily by extending ApplictionBase. Here's a quick example:
The most important thing to remeber is that your class is public. Then, all you need to do is drop your assembly in the /bin folder and Umbraco will pick it up.
Hope this helps.
-- Nik
Ooops...left some code in there that you can ignore:
Cheers.
Thanks guys
Exactly what I was looking for
/Paul S
is working on a reply...