SharePoint 2013 New Event Receivers In A Nutshell

As a developer, knowing how to utilize event receivers is a must have skill in your toolbox. In SharePoint 2013 there were three major changes to Event Receivers and two minor ones. This blog post is an overview of what’s new.

The Evolution of SharePoint Event Receiver Type Enumeration

The chart below shows the progression of additions to the event receiver options in SharePoint. So far nothing has been deprecated, so each progressive release includes all the previous ones.

 

1. Remote Event Receivers
“Remote event receivers handle events that occur on an item in the app, such as a list, a list item, or a web. These events resemble those in a traditional SharePoint solution, except that they can work with the remote components of the app for SharePoint.” – http://msdn.microsoft.com/en-us/library/office/dn456315.aspx

Here are the key takeaways for remote events.

  • They can only handle a subset of events which have been traditionally available.
  • They are now available for Apps.
  • Because they call an external web service, they are only available in Auto-hosted and Provider-hosted Apps. They do not work with SharePoint-hosted Apps.

2. App Event Receiver
Now that you are familiar with Remote Events, we can now discuss App Events. These special events allow developers some control during the App lifecycle process. They are raised in the following three instances.

  1. After an App is installed.
  2. After an App is upgraded.
  3. While and App is uninstalling.

They are set in Visual Studio in the properties for the App, shown here.

Note:

 

3. Entity Instance Events
Basically this is an event receiver that gives you developer access to three events which occur when External Content Types (registered in BCS) are added, updated, or deleted. Unfortunately there is almost no information regarding this that I can find.

4. Security Event Receiver
I have briefly covered this topic before and now it is being discussed in the larger context of all the event receiver updates to SharePoint 2013. This server side only event receiver (SPSecurityEventReceiver) has received almost no fanfare since SharePoint 2013 was released. It can; however, be utilized in a variety of fashions that are extremely useful. The following are the list of events available to developers in the SPSecurityEventReceiver.

  • GroupAdded – Specifies an event that occurs after a security group is added.
  • GroupAdding – Specifies an event that occurs before a security group is added.
  • GroupDeleted – Specifies an event that occurs after a security group is deleted.
  • GroupDeleting – Specifies an event that occurs before a security group is deleted.
  • GroupUpdated – Specifies an event that occurs after a security group is updated.
  • GroupUpdating – Specifies an event that occurs before a security group is updated.
  • GroupUserAdded – Specifies an event that occurs after a user is added to a security group.
  • GroupUserAdding – Specifies an event that occurs before a user is added to a security group.
  • GroupUserDeleted – Specifies an event that occurs after a user is deleted from a security group.
  • GroupUserDeleting – Specifies an event that occurs before a user is deleted from a security group.
  • InheritanceBreaking – Specifies an event that occurs before an inheritance is broken.
  • InheritanceBroken – Specifies an event that occurs after an inheritance is broken.
  • InheritanceReset – Specifies an event that occurs after the role inheritance is restored.
  • InheritanceResetting – Specifies an event that occurs before the role inheritance is restored.
  • RoleAssignmentAdded – Specifies an event that occurs after a role assignment is added.
  • RoleAssignmentAdding – Specifies an event that occurs before a role assignment is added.
  • RoleAssignmentDeleted – Specifies an event that occurs after a role assignment is deleted.
  • RoleAssignmentDeleting – Specifies an event that occurs before a role assignment is deleted.
  • RoleDefinitionAdded – Specifies an event that occurs after a role definition is added.
  • RoleDefinitionAdding – Specifies an event that occurs before a role definition is added.
  • RoleDefinitionDeleted – Specifies an event that occurs after a role definition is deleted.
  • RoleDefinitionDeleting – Specifies an event that occurs before a role definition is deleted.
  • RoleDefinitionUpdated – Specifies an event that occurs after a role definition is updated.
  • RoleDefinitionUpdating – Specifies an event that occurs before a role definition is updated.

http://msdn.microsoft.com/en-us/library/sharepoint/microsoft.sharepoint.spsecurityeventreceiver_members.aspx

5. List Item Version Events
Lost in all this, is a small update to the SPItemEventReceiver class. There is now a way to handle events when an item or file version is deleted (ItemVersionDeleted) or is being deleted (ItemVersionDeleting). This can be helpful for records management or archival purposes.

Conclusion
The evolution of event receivers patterns the overall evolution of SharePoint itself. There are some “under the hood” (server side) enhancements but the biggest features are App related and cloud compatible. There are many positives to this evolution, my personal favorite is the emergence of the “bring your own web service” architecture. Please leave comments for discussion, any good links, or a reference for the Entity Instance events.

Tim Ferro

Leave a Comment