Sunday, August 24, 2008

How to get previous value of listitem in ItemUpdating event

Hi All,

We have event handlers assigned to the list. Lets say when item is added or updated we trigger the event and handle the event by writing our custom code.

The problem happens many times when you require to know that what was the previously entered value if you handle the updating event. Getting the earlier value (before modification done i.e before updated called) in updating is possible so that we come to know that what was the previous value and what is the new changed value of list item.

All you need to do is write a simple code mentioned below:

SPListItem item = properties.ListItem;

string strAmounr = string.Empty;

if (item["Amount"] != null)
strAmounr = item["Amount"].ToString();

The above code actually gives you the previous value of the Amount column.

Now let's get the new entered value in Amount column of the list.

string strNewAmount = properties.AfterProperties["Amount"].ToString();

Simple!!!! Now you have new value of Amount too. so just compare them and perform your steps.

That's it. your job is done.


Anonymous said...

this would be magnificent if it actually worked. It's possible that I am trying to get the CHANGED value of a list column in wss; the listItem[] gets the current value, the AFTER and BEFORE properties are nothing. and this just gets values changed in code???

Anonymous said...

ignore my previous comment, there was an issue with the id10t behind the monitor

Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to