This is an attempt to bring the same functionalities of Server Side Object Model (SSOM) into SharePoint Online also.
This method is very useful, if you wanted to retain the Modified By and Modified Date on your SharePoint list for Auditing purpose when you migrate to SharePoint Online.
Its appropriate to understand the difference but List Item's Update method and System Update method.
If you want to update the fields Modified, Modified by then you can explicitly assign the new values to its field or you can also ignore when you call the method Item.Update().
If you wish to retain the Modified and Modified By column but wanted to update the rest of the fields, then you should use the Item's SystemUpdate method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | var pwd = "yourpassword"; var securePassword = new SecureString(); foreach (char c in pwd) { securePassword.AppendChar(c); } var onlineCredentials = new SharePointOnlineCredentials("murugesan@codethinker.onmicrosoft.com", securePassword); var context = new ClientContext("https://codethinker.sharepoint.com/"); context.Credentials = onlineCredentials; List oList = context.Web.Lists.GetByTitle("Friends"); context.ExecuteQuery(); ListItem item = oList.GetItemById(35); item["xm2s"] = "+91-xxx-7887-xxxx"; item["Modified"] = DateTime.Now.AddDays(-7); item.SystemUpdate(); context.ExecuteQuery(); |
Image 1 |
Earlier my record has old value for the column
Image 2 |
After I call the SystemUpdate method as above Image 1, It updates only the mobile not Modifield column.