BeforeProperties and AfterProperties in Event Receiver in SharePoint 2013

InfoPath alternatives for form designing SharePoint

Here we will discuss about BeforeProperties and AfterProperties in Event Receiver in SharePoint 2013. These properties are useful to get previous values and the current value in the event receiver events. Recently we got a requirement to get the save the previous value before updating in SharePoint 2013. In case of ItemUpdating event it is possible to get the previous value by using the properties.ListItem property and in the AfterProperties we wil be able to get the updated value. You can also see how we can disable event firing in SharePoint list item update.

Also see a good article on Event Receivers in SharePoint.

You may like to read:

– CAML Query Designer in Sharepoint 2013 Online

– Updating a Custom App in SharePoint 2013

– Create a responsive mobile master page using SharePoint 2013 designer

Before starting this you can check out the how we can create event handler using Visual Studio.

The behavior of BeforeProperties and AfterProperties are different for list and document library. 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 list items.

Below is the matrix for both list and document library.

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

For 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”;

    }

}

Similar SharePoint 2013 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 →

Leave a Reply