BeforeProperties and AfterProperties in Event Receiver in SharePoint

This SharePoint tutorial, we will discuss BeforeProperties and AfterProperties in Event Receiver in SharePoint 2013. We will use the BeforeProperties and AfterProperties in Event Receivers in SharePoint 2013/2016.

Before and afterProperties are used to get previous values and the current value in the event receiver events in SharePoint. Learn about before properties afterproperties itemupdated in SharePoint 2013.

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

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

Recently we got a requirement to get save the previous value before updating in SharePoint 2013. In the case of the 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 lists and document libraries in SharePoint 2013/2016.

BeforeProperties and AfterProperties for SharePoint List

ListBeforePropertiesAfterPropertiesproperties.ListItem
ItemAddingNo ValueNew ValueNull
ItemAddedNo ValueNew ValueNew Value
ItemUpdatingNo ValueChanged ValueOriginal Value
ItemUpdatedNo ValueChanged ValueChanged Value
ItemDeletingNo ValueNo ValueOriginal Value
ItemDeletedNo ValueNo ValueNull

BeforeProperties and AfterProperties for SharePoint Document Library

LibraryBeforePropertiesAfterPropertiesproperties.ListItem
ItemAddingNo ValueNo ValueNull
ItemAddedNo ValueNo ValueNew Value
ItemUpdatingOriginal ValueChanged ValueOriginal Value
ItemUpdatedOriginal ValueChanged ValueChanged Value
ItemDeletingNo ValueNo ValueOriginal Value
ItemDeletedNo ValueNo ValueNull

For both lists and libraries:

  • No value: Column value is not available
  • New value: This is the column’s 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 tutorials:

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

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>