I had some time so I decided to add the counterparts to the gl-addeventreceiver command that I just published. I created two new commands, gl-deleteeventreceiver and gl-enumeventreceivers. This post will cover the delete command and I’ll go over the enum command in my next post.
From a code perspective the delete command is very similar to the add command. The main difference (aside from the obvious call to Delete instead of Add) is that I’ve made the assembly, class, and type parameters optional (though at least one must be provided) so the code to get the event receiver to delete needed to be expanded so that it now evaluates each receiver and checks to see if a valid match is found. Once all the receivers have been identified then we simply delete them all.
The help for the command is shown below:
C:\>stsadm -help gl-deleteeventreceiver stsadm -o gl-deleteeventreceiver Deletes an event receiver from a list, web, or content type. Parameters: -url <web or list URL> -target <site | list | contenttype> [-assembly <assembly>] [-class <class name>] [-type <itemadding | itemupdating | itemdeleting | itemcheckingin | itemcheckingout | itemuncheckingout | itemattachmentadding | itemattachmentdeleting | itemfilemoving | fieldadding | fieldupdating | fielddeleting | sitedeleting | webdeleting | webmoving | itemadded | itemupdated | itemdeleted | itemcheckedin | itemcheckedout | itemuncheckedout | itemattachmentadded | itemattachmentdeleted | itemfilemoved | itemfileconverted | fieldadded | fieldupdated | fielddeleted | sitedeleted | webdeleted | webmoved | emailreceived | contextevent | invalidreceiver>] [-contenttype <content type name if target is ContentType>]
The following table summarizes the command and its various parameters:
|Command Name||Availability||Build Date|
|gl-deleteeventreceiver||WSS v3, MOSS 2007||Released: 9/13/2008
|Parameter Name||Short Form||Required||Description||Example Usage|
|url||Yes||The URL to the web or list to remove the event receiver from.||-url http://portal/pages|
|assembly||a||No||The fully qualified assembly name containing the event receiver class to delete from the target.||-assembly "Lapointe.WebPartPageHistory, Version=126.96.36.199, Culture=neutral, PublicKeyToken=3216c23aba16db08"
-a "Lapointe.WebPartPageHistory, Version=188.8.131.52, Culture=neutral, PublicKeyToken=3216c23aba16db08"
|class||c||No||The fully qualified class name of the event receiver to delete from the target.||-class Lapointe.WebPartPageHistory.ListEventReceivers.SourceListEventReceiver
|type||No||The event type to delete.||-type itemupdated|
|target||No||The target type of which the receiver will be deleted. Must be either "list", "site", or "contenttype". If omitted defaults to "list".||-target list|
|contenttype||ct||No, unless target is contenttype||The name of the content type to remove the event receiver from if the target is contenttype.||-contenttype "Page"
The following is an example of how to delete all the event receivers belonging to the web part page history assembly:
stsadm -o gl-deleteeventreceiver -url http://portal/pages -assembly "Lapointe.WebPartPageHistory, Version=184.108.40.206, Culture=neutral, PublicKeyToken=3216c23aba16db08" -target list
Note that you should be particularly careful when deleting event receivers and not specifying the assembly and class attributes as you could inadvertently delete event receivers that are critical to the normal functioning of the list.