Return to doc.sitecore.com

  Sitecore V5 Event
Prev Next

We will achieve the same result with Sitecore V5 event:

  1. HandleSaved method of IItemEventHandler gets invoked on each item save in Sitecore V4. It corresponds to the “item:saved” event of Sitecore V5.
     
  2. “item:saved” event provides exactly the argument we need, that is Item that was saved. We will modify our handler method accordingly: 
// no need to inherit from the base class or implement any interfaces
public class CustomItemHandler
{
  
// using common event handler method signature
   public void OnItemSaved(object sender, EventArgs args)
   {

      
// extracting the event parameter – in this case item that was saved

       Item saved
= Event.ExtractParameter(args, 0) as Item;

// Same logic we had in Sitecore V4, updated to use Sitecore V5 API

       using (new EditContext(saved))

       {

            saved[“Title”] = saved[“Title”].Replace(“*”, “”);

       }

   }

}

then we subscribe our event handler to “item:saved” event in web.config  

<events>

...

   <event name="item:saved">

      <!-- notice the change between how type is described in V4 and V5 -->
      <handler type="CustomItemHandler, CustomItemHandler" method="OnItemSaved"/>

   </event>

    ...

</events>

All other events are handled in the same way. If you have PublishHandler, you will need to subsribe to one of the “publish:begin”, “publish:end” or “publish:fail” events and use the provided Publisher to access the event data.

Supplementary reading:


Prev Next