properties.AfterProperties and properties.BeforeProperties

These two values hold the value of a field Before and After the change event (either an add or update). If it’s in an XXXing event (subc as ItemAdding or ItemUpdating), then the change hasn’t happen yet; if it’s in a XXXed event (such as ItemAdded or ItemUpdated), then the change has occurred.

To get the value:
properties.AfterProperties[“Title”].ToString();


In this example, before an item is updated, we check if the old (before) value is the same as the new (after) value; if not, then don't allow it.
public override void ItemUpdating(SPItemEventProperties properties)

{ if (properties.BeforeProperties[“column”] != properties.AfterProperties[“column”])

{

properties.Cancel = true;

properties.ErrorMessage = “This column cannot be changed”;

}

}

Note: The Before/After value works differently between LIST and DOCUMENT LIBRARY.

For list:

List

BeforeProperties

AfterProperties

properties.ListItem

ItemAdding

No value

New value

Null

ItemAdded

No value

New value

New value

ItemUpdating

No value

Changed value

Original value

ItemUpdated

No value

Changed value

Changed value

ItemDeleting

No value

No value

Original value

ItemDeleted

No value

No value

Null

Here is the same test against a document library:

Library

BeforeProperties

AfterProperties

properties.ListItem

ItemAdding

No value

No value

Null

ItemAdded

No value

No value

New value

ItemUpdating

Original value

Changed value

Original value

ItemUpdated

Original value

Changed value

Changed value

ItemDeleting

No value

No value

Original value

ItemDeleted

No value

No value

Null

Properties.ListItem is the current value of the item at the point of the event.
(info from: http://www.synergyonline.com/blog/blog-moss/Lists/Posts/Post.aspx?ID=25)

* When comparing a <before> and <after> value, sometimes the <before> value is not available; you can use properties.ListItem as the <before> value.

Advertisements
Post a comment or leave a trackback: Trackback URL.

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

%d bloggers like this: