Adding Custom Event Receivers to a List in SharePoint

You can add Custom Event Receivers to a List in SharePoint 2010 using Windows PowerShell. Event Receivers can be used to execute code before or after an Item is created, updated, or deleted. It’s possible to run the code either Synchronous or Asynchronous. The example below demonstrates how you can add a Custom Event Receiver to a List in SharePoint 2010:

PS > $spWeb = Get-SPWeb http://SP01.powershell.nu

PS > $spList = $spWeb.Lists["Tasks"]
PS > $spEvent.Name = "My Event"
PS > $spEvent.Type = "ItemAdded"
PS > $spEvent.Synchronization = "Asynchronous"
PS > $spEvent.SequenceNumber = 3000
PS > $spEvent.Assembly = "My.SharePoint.Event, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a8b0a959bb9389c6"
PS > $spEvent.Class = "My.SharePoint.Event.PowerShellEventReceiver"

PS > $spEvent.Update()
PS > $spWeb.Dispose()

The Type Property will accept a couple of different values such as: Item Added, Item Adding, Field Added and more. To see a complete list of the supported types, you can run the following command in PowerShell:

[System.Enum]::GetNames("Microsoft.SharePoint.SPEventReceiverType")

Twitter This Tip! ReTweet this Tip!


Posted Apr 09 2012, 06:00 AM by sos

Comments

Adding Custom Event Receivers to a List in – SharePoint Tips … | Mastering Sharepoint wrote Adding Custom Event Receivers to a List in – SharePoint Tips … | Mastering Sharepoint
on 04-14-2012 6:59 AM

Pingback from  Adding Custom Event Receivers to a List in – SharePoint Tips … | Mastering Sharepoint

Idera SharePoint Reviews SMBology, Inc. Rackspace Hosting Sponsored by Idera and SharePoint Reviews and SMBology and EPCGroup.net
Copyright 2011 SecretsOfSharePoint.com. All rights reserved.