Suppose I have 10 lists and add a list event receiver itemadded event to these 10 lists, provided that this event provides the same functionality for all 10 lists. It is a headache to add the same event receiver to each list. If there are more than 10 event receivers in the list, copy the same event receiver n times.Code.
The following provides a method. For Multiple lists, if the event receiver requires the same function, you only need to write the code of one event receiver to add it to multiple lists.
1. In your solution, add a feature and register the event receiver for multiple lists in method featureactivated (). The Code is as follows:
Public Override Void Featureactivated (spfeaturereceiverproperties) {spweb oweb = (Spweb) properties. feature. parent; speventreceivertype _ eventtype = Speventreceivertype. itemadded; oweb. Lists [LIST 1]. eventreceivers. Add (_ eventtype, assembly. getexecutingassembly (). fullname, " Eventreceiverproject1.eventreceiver1. eventreceiver1 " ); Oweb. Lists [List 2]. eventreceivers. Add (_ eventtype, assembly. getexecutingassembly (). fullname, " Eventreceiverproject1.eventreceiver1. eventreceiver1 " ); // Add the remaining 10 lists }
2. Create a content type so that all 10 lists use this content type. Then you can attach the event receiver to this content type.
SharePoint: add an event receiver for the content type by encoding