10

I am working on creating event reciever for a custom list in sharepoint 2010 using visual studio..how can this event reciever be targeted to a specific custom list ..in my case its customEmpList?

8

If you want to declaratively attach the event receiver, you may specify ListUrl in the Receivers Element.

<Receivers
  ListTemplateId = "Text"
  ListTemplateOwner = "Text"
  ListUrl = string
  RootWebOnly = TRUE | FALSE
  Scope = Site | Web>
</Receivers>

How to: Create an Event Receiver for a Specific List Instance

4

Create a feature that upon activation have the proper code to attach to a specific list for e.g. :

public override void FeatureActivated(SPFeatureReceiverProperties properties)   
    {   
       SPWeb site = null;   
       try  
       {   
              //Adds the overridden ItemUpdated Event Receiver to a list   
               site = (SPWeb)properties.Feature.Parent;   
               SPList lst = site.Lists["customEmpList"];   
               string asmName = "AssemblyNameOfYourEventHandler, Version=1.0.0.0, Culture=neutral,  PublicKeyToken=EnterThePublicKeyTokenHere";   
               string itemReceiverName = "Namespace.ClassOfEventHandler";   
               lst.EventReceivers.Add(SPEventReceiverType.ItemUpdated, asmName, itemReceiverName);   
               lst.Update() 
        } 
     catch (Exception ex)
      {

      }


     finally
     {

       site.Dispose();

     }

}

The following link contains other possible ways of attaching event handlers : http://blogs.msdn.com/b/brianwilson/archive/2007/03/18/event-handlers-part-3-register-event-handlers-plus-free-site-settings-manage-event-handlers-add-on.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.