How to create OnItemSaved ItemEventHandler when an item is saved in Sitecore

using System;
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Events;

namespace Website.logic.Helper

{
    public class ItemEventHandler
    {
        public void OnItemSaved(object sender, EventArgs args)

        {
            SitecoreEventArgs eventArgs = args as SitecoreEventArgs;

            try
            {

                Assert.IsNotNull(eventArgs, "eventArgs");
                Item savedItem = eventArgs.Parameters[0] asItem;
                Assert.IsNotNull(savedItem, "savedItem");

            } 
            catch (Exception ex)
            {
                Log.Error("Error OnItemSaved ", ex, this);
            }
        }
    }
}

Make sure to update web.config and add your entry just right after see below:

<event name="item:saved">
<handler type="Website.logic.Helper.ItemEventHandler, Website" method="OnItemSaved"/>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s