0

How can I add single event receiver to multiple Lists?

  • Is it for a particular list type or "random" lists in your site ? – JayHell Aug 4 '15 at 14:42
0

You can have one content type that is used in all lists and then attach the event receiver to this content type. This will solve your problem.

0

In the Elements.xml schema, you can have multiple Receivers elements. The receivers element have a property "ListUrl" that you can use to bind your receiver.

<Elements>
  <Receivers
     ListUrl="lists/yourlist">
     <Receiver>
         <Receiver>
           ...
           <Assembly>assemblydef</Assembly>
           <Class>classdef</Class>
           ...
         <Receiver/>
     <Receiver/>
  </Receivers>
  <Receivers
      ListUrl="lists/yourlist2">
      <Receiver>
        ...
        <Assembly>assemblydef</Assembly>
        <Class>classdef</Class>
        ...
      <Receiver/>
   </Receivers>
</Elements>
0

One approach is:

1) Create a content type

2) Attach the "content type" to one or more lists

3) Associate the event to "content type" programmatically

Sample code to point 1:

public static void agregarEventoTipoContenido(string clase, SPContentType tipoContenido, string ensamblado, SPEventReceiverType eventReceiverType, SPEventReceiverSynchronization sincro)
        {
            SPEventReceiverDefinition eventReceiver = tipoContenido.EventReceivers.Add();
            eventReceiver.Synchronization = sincro;
            eventReceiver.Type = eventReceiverType;
            eventReceiver.Assembly = ensamblado;
            eventReceiver.Class = clase;
            eventReceiver.HostType = SPEventHostType.ContentType;
            eventReceiver.Update();
        }

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.