SpItemEventReciever , How to Implement ?(sptechytalks.blogspot.com)
submitted by
Freddy_Khalaf(35) 2 years, 11 months ago
one of the main problems that faces sharepoint programmers is to attach event handler class that responses to events that occurs to sharepoint elements as items , lists & files...
there are few steps we will make that will make attaching event handlers very easy to implement ;
the steps are:
1. Make a new class in your solution and make the class inherits from SPItemEventReceiver this class i ve talked about it in the previous post , this class couldnt be instantiated , its only could be inherited , so you can override the events implemented in this class and make your own event handlers.
2. after you write your event handlers , you must define the lists or items that your events will listen or monitor the events you need to catch and handle them.
to define them you need to write two xml sheets that will define the scope you will monitor to catch your events , the two xml sheets are : a. Feature.xml , b. Element.xml
a. Feature.xml :
we define in it our dll that is produced from our class that will catch the events and implement them and refers to the element.xml sheet that minimizes the scope of monitoring.
b. Element.xml :
as i ve said , this file minimizes the scope of monitoring , without it we can catch for example all the itemupdate events fired in all the site in any list under any subsite , but practically this is not useful so we need to define our scope.
the following code illustrates Feature and Element xml sheets:
Feature.xml :
Id : refers to the produced dll Id .
Feature Scope : here , our scope is all the site ( web ) .
we can remove the tags of to make our scope is the whole web.
Element.xml :
now we will discuss the elements in between the reciever tags and dicuss each of them
Name: we write here a name that describes our event handler.
Type: here we usually write the name of the event such as ItemAdded , ItemUpdated.
then define your assembly and your class as represented in the attached image.
ListTemplateId= for lists and document libraries we use id= 101 , but for Photo Galleries we use id=100
To see all Ids go to : http://msdn.microsoft.com/en-us/library/ms431081.aspx
and to install the previous two files you can read it from http://msdn.microsoft.com/en-us/library/ms453149.aspx
3.after that build your project and place your dlls in GAC at Local_Drive:\WINDOWS\assembly
but by that you wont be able to debug your solution to allow debugging , make the following;
1.open Run a
|category: ASP.NET
|Views: 1
tags:
ASP.NET another
Everyones tags:
Your Tags: