Posts

Showing posts from May, 2012

Working with BeforeProperties and AfterProperties on SPItemEventReceiver

As many of you know, event receivers are a great way to hook into various SharePoint events.  These can apply to Feature events such as FeatureActivated, List events such as FieldAdded, and many others.  The most common set of receivers used, however, are part of SPItemEventReceiver which let you wire your code up to a number of events that can occur to items on a list or library. When working with events, you’ll quickly find that before (synchronous) and after (asynchronous) events exist, and the method suffix such as “ing” (e.g. ItemAdding) and “ed” (e.g. ItemAdded) will tell you whether it gets invoked before or after the actual change is made.  Basic stuff. And, as you get deeper, you’ll even find that you can extract the before and after state of the change.  For example, you can hook into the ItemUpdating event for a document library and prevent a user from changing a certain column.  The code might look like this: public override void It...

Event Receiver enhancements in SharePoint 2010

Image
With SharePoint 2010, there are some good enhancements in Event Receivers. New Events New Registration technique Synchronous After-Events Custom error pages and redirection  Impersonation enhancements ( SPEventPropertiesBase.OriginatingUserToken ) List of Events : http://msdn.microsoft.com/en-us/library/ms437502.aspx   Lets discuss one by one. 1. New Events As part of SharePoint 2010, there are six new events that you can take advantage of. These events allow you to capture creation and provisioning of new webs and the creation and deletion of lists.  Event Name  Event Description  Event Receiver Class WebAdding A synchronous event that happens before the web is added. Some URL properties may not exist yet for the new site, since the new site does not exist yet. SPWebEventReceiver WebProvisioned A synchronous or asynchronous after-event that occurs after the web is created. You ma...