Understanding SPItemEventReciever class in Sharepoint

SPItemEventReciever; ( msdn is a reference )


This class will be very useful to all sharepoint users and developers who integrates both ASP.NET and Sharepoint together.


First of all,


what is SPItemEventReciever? 


its a class that can't be instantiated, which means that we cant create an object from it, but this class is used as a parent class to the class that handles or overrides the events done to any list item in my Sharepoint site.


when SPItemEventReciever can be used ? 


it can be used when you want to override any event that done to a list item in a sharepoint list such as:


1. ItemAdded.

2. ItemAdding.

3. ItemDeleted.

4. ItemDeletion.


and many other events like adding attachments to lists, and moving list items. These events can replace some workflows that are simple like workflows that add the item to more than one list, as we can add an item to a list, and by overriding the event of ItemAdding we can add the same item in other lists , or we can override the ItemDeleting function and delete an item from more than one list.


I will show you some code sample that will show how to implement these events in the next post. This blog is just a simple introduction to SPItemEventReciever.


One of the most frequently asked questions about this class is -


What are the parameters for overriding ItemDeleting or ItemAdding events?


These functions can be overridden like this:


public override void ItemDeleting(SPItemEventProperties properties)

{


}


So what does this SPItemEventProperties object contains?


If you look at this class closely, you will find following members:


ListItemId = which is the id of the item the event is done to it.

ListTitle = gets the Title of the list you re working on.

WebUrl = gets the web url you re working in.

SiteId = Gets the ID of the site in which the event occurred.


These are the most important properties available in this class.


This post was an introduction to SPItemEventReciever class. In my next post, I will write some code examples that shows how to use this class.