EnjoySharePoint YouTube Channel

BeforeProperties and AfterProperties in Event Receiver in SharePoint 2013


Here we will discuss BeforeProperties and AfterProperties in Event Receiver in SharePoint 2013. These properties are used to get previous values and the current value in the event receiver events. Learn about before properties afterproperties itemupdated in SharePoint 2013.

Get Office 365 Enterprise E3 Or Business Premium Subscription & Try out all the features

Before properties are used to get previous values in the event receiver events in SharePoint 2013.

After properties are used to get current values in the event receiver events in SharePoint 2013.

Recently we got a requirement to get the save the previous value before updating in SharePoint 2013. In the case of ItemUpdating event, it is possible to get the previous value by using the properties.ListItem property and in the AfterProperties, we will be able to get the updated value.

The behavior of BeforeProperties and AfterProperties are different for list and document library in SharePoint 2013.

According to MSDN, For documents, Before and After properties are guaranteed for post events, such as ItemUpdated, but Before properties are not available for post events on SharePoint 2013 list items.

Below is the matrix for both list and document library in SharePoint 2013.

BeforeProperties and AfterProperties for SharePoint 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

BeforeProperties and AfterProperties for SharePoint 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

For both lists and libraries:

No value: Column value is not available

New value: This is the column new value.

Changed value: Updated Column value

Original value: This is the Old value, not the updated value.

If you want to compare a column value from the old value with updated value, then you can write like below:

public override void  ItemUpdating(SPItemEventProperties properties)

{

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

    {

        properties.Cancel = true;

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

    }

}

You may like following SharePoint event receivers tutorials:

Hope this SharePoint tutorial helps to understand BeforeProperties and AfterProperties in event receiver in SharePoint 2013.

Check out Best Alternative to InfoPath -> Try Now
You May Also like the Following SharePoint Tutorials:

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →