SharePoint Event Receivers

SharePoint contains list and libraries which allow you to store and organize your content. At first glance, this content seems fairly static, it just sits there until someone makes changes to it. What if you want your content to trigger actions that take place in your system? Here are a few examples:

  • When you add a list item you would like to prevent the user from saving the item until they meet specific validation requirements.
  • Synchronize content between sites, for example copy an announcement made on a department site to the company root site.
  • Prevent certain sites or content from being deleted.
  • Create your own custom logging when a specific type of content is added to the system.
  • Automatically add metadata to your content based which library or site it is added to.
  • Call a service to another application

These scenarios, and many more, can be handled by Event Receivers in SharePoint. When an event occurs, such as an item is added to a list, an event is triggered. Custom code can be associated with the event, and this code will run when the event is triggered, allowing us to do anything we want with that content during or after the event occurs.

There are also two types of events that can occur. "After" events occur after the event completes while "Before" events occur before the event completes. The "Before" events allow us to do validation and even prevent the event from occurring if necessary.

SharePoint 2010 Event Receivers

Here is a list of operations that can trigger Event Receivers in SharePoint 2010

Sites

  • A site collection has been deleted
  • A site collection is being deleted
  • A web has been added
  • A web has been provisioned
  • A web has been deleted
  • A web is being deleted
  • A web has been moved
  • A web is being moved

Lists

  • A list is being added
  • A list has been added
  • A list is being deleted
  • A list has been deleted

Fields

  • A field is being added
  • A field has been added
  • A field is being deleted
  • A field has been deleted
  • A field is being updated
  • A field has been update

List Items and Files

  • An item is being added
  • An item has been added
  • An item is being deleted
  • An item has been deleted
  • An item is being updated
  • An item has been updated
  • An item has been converted
  • An item is being moved
  • An item has been moved
  • An item is being checked in
  • An item has been checked in
  • An item is being checked out
  • An item has been checked out
  • An attachment is being added
  • An attachment has been added
  • An attachment is being deleted
  • An attachment has been deleted

Email

  • An email has been received (Incoming email on a library)

Workflows

  • A workflow is being started
  • A workflow has been started
  • A workflow has been completed
  • A workflow has been postponed

SharePoint 2013 Event Receivers

In addition to supporting all of the Event Receivers provided by SharePoint 2010, Microsoft has added many new Event Receivers in SharePoint 2013 including:

SharePoint Groups

  • A SharePoint Group is being added
  • A SharePoint Group has been added
  • A SharePoint Group is being deleted
  • A SharePoint Group has been deleted
  • A SharePoint Group is being updated
  • A SharePoint Group has been updated

User Security

  • A user is being added to a SharePoint Group
  • A user has been added to a SharePoint Group
  • A user is being deleted from a SharePoint Group
  • A user has been deleted from a SharePoint Group
  • user's Role Assignment is being added
  • user's Role Assignment has been added
  • user's Role Assignment is being deleted
  • user's Role Assignment has been deleted
  • A user's Role Definition is being added
  • A user's Role Definition has been added
  • A user's Role Definition is being deleted
  • A user's Role Definition has been deleted
  • A user's Role Definition is being updated
  • A user's Role Definition has been updated

Security Inheritance

  • Inheritance is being broken
  • Inheritance has been broken
  • Inheritance is being reset
  • Inheritance has been reset

Remote Event Receivers

These scenarios, and many more, can be handled by Event Receivers in SharePoint. When an event occurs, such as an item is added to a list, an event is triggered. Custom code can be associated with the event, and this code will run when the event is triggered, allowing us to do anything we want with that content during or after the event occurs.