Notes for adding and deleting eventhander

Source: Internet
Author: User

Public override void featureactivated (spfeaturereceiverproperties properties)
{
Try
{
Using (spsite site = new spsite (spsite) properties. feature. Parent). url ))
{
String shortename = "demetersoft. kipformoss. workflow. feature. eventhandler, version = 1.0.0.0, culture = neutral, publickeytoken = 486e336fb7c97750 ";
String eventhandlernamespace = "demetersoft. kipformoss. workflow. feature. eventhandler .";
String hqreceivedoclib_itemupdatedname = "hqreceivedoclib_eventhandler ";
String hqissuedoclib_itemupdatedname = "hqissuedoclib_eventhandler ";

Splist hqreceivedoclib = site. rootweb. Lists ["headquarters receiving library"];
Splist hqissuedoclib = site. rootweb. Lists ["headquarters development library"];

For (INT I = 0; I {
Speventreceiverdefinition extends ER = hqissuedoclib. eventreceivers [I];
If (Explorer. Class. Equals (eventhandlernamespace + hqreceivedoclib_itemupdatedname ))
{
Explorer. Delete ();
}
}

For (INT I = 0; I {
Speventreceiverdefinition extends ER = hqissuedoclib. eventreceivers [I];
If (Explorer. Class. Equals (eventhandlernamespace + hqissuedoclib_itemupdatedname ))
{
Explorer. Delete ();
}
}
Hqreceivedoclib. eventreceivers. Add (speventreceivertype. itemupdated, incluename, eventhandlernamespace + hqreceivedoclib_itemupdatedname );
Hqissuedoclib. eventreceivers. Add (speventreceivertype. itemupdated, incluename, eventhandlernamespace + hqissuedoclib_itemupdatedname );
}
}
Catch (exception ex)
{
// Exception Handling
Return;
}

}

First, we need to clear that there may be multiple identical events and they all run
It is best to delete the speventreceiverdefinition. class with the Assembly + class name.
Because you may deploy multiple identical time handles to prevent accidental deletion of other

 

Console test master code

Public static void actiontofeaturereceiver (spsite site)
{

Using (spweb rootweb = site. rootweb)
{
Splist hqdispatchlist = rootweb. Lists ["mytestfolder"];

Speventreceiverdefinitioncollection receivercol = hqdispatchlist. eventreceivers;

String shortename = "demetersoft. kipformoss. workflow. feature. eventhandler, version = 1.0.0.0, culture = neutral, publickeytoken = 486e336fb7c97750 ";
String eventhandlernamespace = "demetersoft. kipformoss. workflow. feature. eventhandler .";
String hqreceivedoclib_itemupdatedname = "hqreceivedoclib_eventhandler ";
String hqissuedoclib_itemupdatedname = "hqissuedoclib_eventhandler ";

For (INT I = 0; I {
Speventreceiverdefinition extends ER = hqdispatchlist. eventreceivers [I];
If (Explorer. Class. Equals (eventhandlernamespace + hqreceivedoclib_itemupdatedname ))
{
Explorer. Delete ();
}
}

Hqdispatchlist. eventreceivers. Add (speventreceivertype. itemupdated, incluename, eventhandlernamespace + hqreceivedoclib_itemupdatedname );
Hqdispatchlist. eventreceivers. Add (speventreceivertype. itemupdated, incluename, eventhandlernamespace + hqissuedoclib_itemupdatedname );

For (INT I = hqdispatchlist. eventreceivers. Count; I> 0; I --)
{
Speventreceiverdefinition extends ER = hqdispatchlist. eventreceivers [I-1];
Console. writeline (aggreger. Class );
Console. writeline (Explorer. GetType (). basetype );
Console. writeline (Explorer. type. tostring ());
Console. writeline ("=========================== ");

}

Console. Readline ();
}
}

 

Output:
Demetersoft. kipformoss. workflow. feature. eventhandler. hqreceivedoclib_eventhandler
System. Object
Itemupdated
======================================
Demetersoft. kipformoss. workflow. feature. eventhandler. hqissuedoclib_eventhandler
System. Object
Itemupdated
======================================

 

 

 

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.