SharePoint 2007 Event model

There is another way to take action on data inside of SharePoint besides using workflows. You can actually tie directly into the events within SharePoint. For example, when a user goes to delete an item from a list, the ItemDeleting event is fired, followed by the ItemDeleted method. This can be incredibly useful in many scenarios. First, simply being able to differentiate between taking action prior to the action actually happening (ItemDeleting) and after the action is complete (ItemDeleted) can be hugely beneficial. For example, suppose you have a list in a site that you have created a roll up based on. If someone comes in and deletes (or modifies) a column that is used by that schema, then your roll up is suddenly broken – leading to troubleshooting time and an unnecessary headache. You could set up permissions to prevent this, but what if the person that is doing the changing has full control or, worse, is a site collection administrator? This scenario plays out daily. Well, using the event model, you can set up an ItemDeleting event that simply cancels the event and return an error message to the user. This methodology removes permissions from the mix entirely. This is a simple example of how useful the event model can be to use, but it shows the power.

The events are tied into by leveraging the Event Receivers. I have found four Event Receivers that are of real interest. They are SPItemEventReceiver, SPListEventReceiver, SPWebEventReceiver and SPSiteEventReceiver coresponding to events on list items, list, webs and sites. Here are lists describing the events that can be tapped into:

Using SPItemEventReceiver

ContextEvent

Item level event reaction to a SPContext class method call.

ItemAdded

Asynchronous After event that occurs after a new item has been added to its containing object.

ItemAdding

Synchronous before event that occurs when a new item is added to its containing object.

ItemAttachmentAdded

Asynchronous after event that occurs after a user adds an attachment to an item.

ItemAttachmentAdding

Synchronous before event that occurs when a user adds an attachment to an item.

ItemAttachmentDeleted

Asynchronous after event that occurs when after a user removes an attachment from an item.

ItemAttachmentDeleting

Synchronous before event that occurs when a user removes an attachment from an item.

ItemCheckedIn

Asynchronous after event that occurs after an item is checked in.

ItemCheckedOut

Asynchronous after event that occurs after an item is checked out.

ItemCheckingIn

Synchronous before event that occurs as a file is being checked in.

ItemCheckingOut

Synchronous before event that occurs after an item is checked out.

ItemDeleted

Asynchronous after event that occurs after an existing item is completely deleted.

ItemDeleting

Synchronous before event that occurs before an existing item is completely deleted.

ItemFileConverted

Asynchronous after event that occurs after a file has been transformed by the SPFile.Convert method.

ItemFileMoved

Occurs after a file is moved.

ItemFileMoving

Occurs when a file is being moved.

ItemUncheckedOut

Synchronous before event that occurs when an item is being unchecked out.

ItemUncheckingOut

Synchronous before event that occurs when an item is being unchecked out.

ItemUpdated

Asynchronous after event that occurs after an existing item is changed, for example, when the user changes data in one or more fields.

ItemUpdating

Synchronous before event that occurs when an existing item is changed, for example, when the user changes data in one or more fields.

Using SPListEventReceiver

FieldAdded

Occurs after a field link is added.

FieldAdding

Occurs when a field link is being added to a content type.

FieldDeleted

Occurs after a field has been removed from the list.

FieldDeleting

Occurs when a field is in the process of being removed from the list.

FieldUpdated

Occurs after a field link has been updated

FieldUpdating

Occurs when a field link is being updated

Using SPSiteEventReceiver

ItemAdded

Asynchronous After event that occurs after a new item has been added to its containing object.

ItemAdding

Synchronous Before event that occurs when a new item is added to its containing object.

ItemAttachmentAdded

Asynchronous After event that occurs after a user adds an attachment to an item.

ItemAttachmentAdding

Synchronous Before event that occurs when a user adds an attachment to an item.

ItemAttachmentDeleted

Asynchronous After event that occurs when after a user removes an attachment from an item.

ItemAttachmentDeleting

Synchronous Before event that occurs when a user removes an attachment from an item.

ItemCheckedIn

Asynchronous After event that occurs after an item is checked in.

ItemCheckedOut

Asynchronous After event that occurs after an item is checked out.

ItemCheckingIn

Synchronous Before event that occurs as a file is being checked in.

ItemCheckingOut

Synchronous Before event that occurs after an item is checked out.

ItemDeleted

Asynchronous After event that occurs after an existing item is completely deleted.

ItemDeleting

Synchronous Before event that occurs before an existing item is completely deleted.

ItemFileConverted

 

ItemFileMoved

Occurs after a file is moved.

ItemFileMoving

Occurs when a file is being moved.

ItemUncheckedOut

Synchronous Before event that occurs when an item is being unchecked out.

ItemUncheckingOut

Synchronous Before event that occurs when an item is being unchecked out.

ItemUpdated

Asynchronous After event that occurs after an existing item is changed, for example, when the user changes data in one or more fields.

ItemUpdating

Synchronous Before event that occurs when an existing item is changed, for example, when the user changes data in one or more fields.

Using SPWebEventReceiver

SiteDeleted

Occurs after a site collection has been deleted.

SiteDeleting

Occurs when a site collection is being deleted.

WebDeleted

Asynchronous After event that occurs after an existing Web site is completely deleted.

WebDeleting

Synchronous Before event that occurs before an existing Web site is completely deleted.

WebMoved

Asynchronous After event that occurs after an existing Web site has been moved.

WebMoving

Synchronous Before event that occurs before an existing Web site has been renamed or moved to a different parent object.

In the next posting, I’ll demonstrate how to actually use this information.

Ninja

Advertisements

About lelandholmquest

After serving in the Navy as a Reactor Operator on fast attack submarines, I earned both a Bachelor's and Masters in Information Technology from American InterContinental University and am currently working on my doctorate. I have a beautiful wife and two of the sweetest daughters a man could ask for. And I work for the greatest company: Microsoft. At Microsoft I work on the knowledge management system for Microsoft Services: Campus on Office 365.
This entry was posted in C# Programming, SharePoint Coding and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s