Eventcycler 2 in SharePoint binds event Cycler to the list type or list instance.

Source: Internet
Author: User

To create an event aggreger, you must create a base class that inherits the event aggreger special from the WSS object model. it is also important to note that the event handler er Class must be compiled to the strongly-namedProgramSet and deployed to GAC.

 

The class in the following example inherits from splisteventreceiver, so it can process list-based events. just like in all the event handler er classes, you can override the methods defined in the base class to create the implementation of the event handler method.

 Using System; Using Microsoft. SharePoint; Namespace Litwaretypes { Public class  Vendorlisteventreceiver : Splisteventreceiver { Public override void Fieldadding (splisteventproperties properties) {properties. errormessage ="You cannot change this List Schema! " ; Properties. Cancel = True ;} Public override void Fieldupdating (splisteventproperties properties) {properties. errormessage = "You cannot change this List Schema! " ; Properties. Cancel = True ;} Public override void Fielddeleting (splisteventproperties properties) {properties. errormessage = "You cannot change this List Schema! " ; Properties. Cancel = True ;}}}

 

This vendorlisteventreceiver provides three event handler by reloading the three methods named fieldadding, fieldupdating, and fielddeleting. because all three events are processed before the event occurs, these event handlers can cancel the event regardless of the event trigger. in this case, the three event handler uses the splisteventproperties parameter to assign an error message and then cancels the event. after these event handler are properly bound to the list, they will prevent users (even users with administrator permissions) from adding, modifying, or deleting any field to the list.

 

Now let's discuss how to bind the event handler in the event handler er Class to a list type. you can bind the element by adding a receiver element to a feature. the receivers element has a 10001 value listtemplateid attribute, which binds receivers to all instances of the custom list type. note that in the receiver element, each event handler has an independent receivers element. you should observe that each event handler method must be bound to its own handler Er element, because no other method can bind multiple event handler at a time.

 <  Elements  Xmlns  = "Http://schemas.microsoft.com/sharepoint/ " > <! --  Receivers element can only be used in feature where scope = web  --> <  Receivers  Listtemplateid  = " 10001 " > <  Cycler  > <  Name  > Field adding event </ Name  > <  Type  > Fieldadding </  Type  > <  Assembly  > Litwaretypes, [full 4-part assembly name goes here] </  Assembly  > <  Class  > Litwaretypes. vendorlisteventreceiver </ Class  > <  Sequencenumber  > 1000 </  Sequencenumber  > </  Cycler  > <  Cycler  > <  Name  > Field updating event </  Name  > < Type  > Fieldupdating </  Type  > <  Assembly  > Litwaretypes, [full 4-part assembly name goes here] </  Assembly  > <  Class  > Litwaretypes. vendorlisteventreceiver </  Class  > < Sequencenumber  > 1000 </  Sequencenumber  > </  Cycler  > <  Cycler  > <  Name  > Field deleting event </  Name  > <  Type  > Fielddeleting</  Type  > <  Assembly  > Litwaretypes, [full 4-part assembly name goes here] </  Assembly  > <  Class  > Litwaretypes. vendorlisteventreceiver </  Class  > <  Sequencenumber  > 1000</  Sequencenumber  > </  Cycler  > </  Receivers  > </  Elements  > 

 

The above technology of binding Event Handler through receivers element has several notable limitations.

    • First, the receivers element can only be used in features within the site range. it cannot be used in feature with other levels of scope, which means that we cannot use the feature at the site level of this event-binding technology.
    • Second, the handler element only allows you to bind event handler to a list type. it does not provide you with the flexibility to bind event handlers to the list instance or to a content type. in many cases, you need WSS object model to bind your event handler, because the object model provides more flexibility.

Now let's discuss how to bind event handlers to a list instance instead of a list type. the following example shows how to bind the event handler of the vendorlistreceiver class to the list instance named vendors using the WSS object model. hereCodeIt is written in the featureactived method. When you add event handler in this way, the information bound to the event will be written into the content database, just like other custom modification targets.

 Public override void Featureactivated (spfeaturereceiverproperties properties) {spsite sitecollection = (spsite) properties. feature. parent; spweb site = sitecollection. rootweb; splist lstvendors = site. Lists [ "Vendors" ]; String Asmname = "Litwaretypes, [full 4-part assembly name goes here]" ; String Listreceivername ="Litwaretypes. vendorlisteventreceiver" ; // Add event handler er to fire before new column is added Lstvendors. eventreceivers. Add (speventreceivertype. fieldadding, asmname, listreceivername ); // Add event handler er to fire before existing column is updated Lstvendors. eventreceivers. Add (speventreceivertype. fieldupdating, asmname, listreceivername ); // Add event handler er to fire before existing column is updated Lstvendors. eventreceivers. Add (speventreceivertype. fielddeleting, asmname, listreceivername );}

Translated from:

inside Microsoft Windows SharePoint Services 3.0

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.