Before learning new enhancements in sharepoint2010, we have to know why they were enhanced. So that we can remember new features easily, below are the limitations on sharepoint2007 what I covered in my development career.
- Cannot hook the events to a particular SharePoint lists.
- Need to use standard pre-defined error page when canceling the events, which is not so intuitive for the end users
- No events for SPWeb object.
Enhancements in event receivers:
Custom Error Pages: SharePoint 2010 provides developers to create/redirect to custom error pages when the events are cancelled. This gives developers a great flexibility to provide more information on the custom error pages. The redirection will applicable only for the pre-synchronous events and not for post-synchronous events like ListAdded, etc., below shows the code snippets to redirect to custom error page.
properties.Cancel = true;
properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
properties.RedirectUrl = "/_layouts/CustomErrors/error.aspx";
Event Registration Feature: With new event registration enhancement, developers are able to hook the event to a particular SharePoint list in the elements.xml file using ListUrl node by passing relative URL of the list. Developers are now able to scope the events either at Site or Web levels and also set the property RootWebOnly in Receivers node, if the event receiver only works for root site.
Impersonation Improvements: Developers are able to elevate the privileges in the event receivers in order to perform some tasks, which current user who triggered the event does not have adequate permissions to do so using SPSecurity.RunWithElevatedPrivileges method. In SharePoint 2010, there are new properties namely OriginatingUserToken, UserDisplayName and UserLoginName which help the developers to revert back to the original user who triggered the event very easily.
Reduced the usage of “Feature Stapling” functionality by implementing “A site is being provisioned and A site was provisioned”
"Feature Stapling means, let’s say we create one simple feature of creating list with few columns and if we want to have this list created every time blank site or team site is created, then we can register this feature to be used in team site and blank site, so that whenever we create team site or blank site, the list gets created"
If you want detailed explanation on "feature stapling", please refer this link http://sharepointmagazine.net/articles/introduction-to-sharepoint-feature-stapling-part-1