SharePoint: Add a list event receiver with the same function to multiple lists SharePoint: add an event receiver for the content type by encoding

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.