Monday, March 19, 2012

Quick Notes: Retrieving Values in Event Receivers using BeforeProperties and AfterProperties

In SharePoint Portal development there are many scenarios where we need to develop event receivers.
So for accessing list item/ library item values, we need to use BeforeProperties and AfterProperties of SharePoint Event receivers. But some times they give empty or null values.
Below chart gives great understanding of which values are populated in BeforeProperties , AfterProperties and properties.ListItem objects.

For list:



List

BeforeProperties

properties.ListItem

AfterProperties

ItemAdding

Empty

Null

New Value

ItemAdded

Empty

New Value

New Value

ItemUpdating

Empty

Old Values

Updated Values

ItemUpdated

Empty

Updated Values

Updated Values

ItemDeleting

Empty

Original Values

Empty

ItemDeleted

Empty

Null

Empty

For library:


List

BeforeProperties

properties.ListItem

AfterProperties

ItemAdding

Empty

Null

Empty

ItemAdded

Empty

New Value

Empty

ItemUpdating

Old Values

Old Values

Updated Values

ItemUpdated

Old Values

Updated Values

Updated Values

ItemDeleting

Empty

Original Values

Empty

ItemDeleted

Empty

Null

Empty


The Synergy MOSS blog has explain this more clearly, please check here for more details.
Good Post on "SP 2010: How To – Event Receivers and Custom Error Pages" by Tobias Zimmergren . 
http://zimmergren.net/technical/sp-2010-how-to-event-receivers-and-custom-error-pages