Jan 3, 2015

Update Vs SystemUpdate in SharePoint

Hi Guys,

In this post i am going to explain what is the difference between Update and SystemUpdate methods. As you all know, these two methods are used to update/add the item in the sharepoint list like below. Here I am adding some more points on the same..


  1.        SPList lstProducts = web.Lists.TryGetList("Products");  
  2.        SPListItem prodItem = lstProducts.Items.Add();  
  3.        prodItem["ProdName"] = "PCMMigrator";  
  4.        prodItem["Category"] = "Sharepoint";  
  5.        prodItem.Update();
  6.       //prodItem.SystemUpdate();


Update() :

In the above code the Update() method adds the data to the SharePoint Products list. When this is happening it also internally updates the built in fields the "Modified  with the timestamp of the server when it is updating" and "Modified By with the user who logged in" . And also a new version is created for the item (if versioning enabled for the list).

SystemUpdate() :

It updates the data to the SharePoint list without changing the built in Modified and Modified By fields. It will not create any new version for the item. Basically this method does all the updates to the content database directly.

This method also can be written with boolean argument.

SystemUpdate(false) is equivalent to SystemUpdate()
SystemUpdate(true) is equivalent to SystemUpdate() but creates the new version for the item.

The SystemUpdate also triggers all  the list events as the update does.

In Server Object Model we can use these both Update and SystemUpdate methods. But the client object model will not allow the SystemUpdate method as it is changing data in content db directly without server knowing the changes made. If really we want to achieve this in csom, there are some alternative ways like writing a custom webservice and calling it in csom code.

Hope this is useful,

Thanks,
Purna

1 comment: