One very useful area of Sitecore is the ability to subscribe to system events. Examples are things like when items are saved (item:saved), items are published etc.
All the out the box events can be seen within the <events> section of the config.
You can subscribe to events via config:
1 2 3 4 5 6 7 8 9 |
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> <sitecore> <events> <event name="cta:saved"> <handler type="###.Shell.Events.CtaItemSaveHandler, ###" method="SaveCtaItem" /> </event> </events> </sitecore> </configuration> |
and raise your own custom events via:
1 2 3 4 |
Event.RaiseEvent("cta:saved", new object[] { context.Items[0] }); |
One thing to note, events such as item:saved will be run when sometimes you don’t expect it. Examples are package installations.
You can guard against custom event handlers running during package installations if you check for the existence of the current httpContext:
1 2 3 4 5 6 7 8 9 10 11 12 |
class MyEventHandler { void ProcessEvent(...) { if (HttpContext.Current == null) { return; } //code to process event... } } |
For more info on how to make use of Sitecore events, have a look at http://sdn.sitecore.net/Articles/API/Using%20Events.aspx
Hi there, always i used to check blog posts here in the early hours
in the daylight, because i enjoy to find out more and more.