Follow in Twitter & Facebook



Like in Facebook

Powered By Blogger Widgets

Free Download

FREE Tools



Tuesday, August 28, 2012

Adding Custom Event Receivers to a List

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://siteurl
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.




0 on: "Adding Custom Event Receivers to a List"