Basically, when we are trying to update a SharePoint List Item/Document then the item/file version is increased according to the list versioning. In the Server side object model, we can update a List Item without increasing its file version by setting ‘SystemUpdate’ as false. But in CSOM ‘SystemUpdate’ property is not supported.

In this below code block, I have mentioned how we can update a Listitem/file without changing item/file version number by using “ValidateUpdateListItem” method.

I have used a sample console application to achieve the goal. I have executed the below code sample for an SPO (O365) server and this will also work for all other SharePoint server versions except SP 2010 server.

In the code sample, I have updated the ‘Modified User’ and ‘Modified Date’ field of a SharePoint document.

The code block for this is as mentioned below,

  1. using System;
  2. using System.Security;
  3. using System.Collections.Generic;
  4. using Microsoft.SharePoint.Client;
  5. namespace ConsoleApp1 {
  6. class Program {
  7. static void Main(string[] args) {
  8. List list = null;
  9. Web web = null;
  10. User modifiedBy = null;
  11. ListItem item = null;
  12. ClientContext context = null;
  13. ListItemCollection itemCollection = null;
  14. SecureString pswd = new SecureString();
  15. string userName = string.Empty;
  16. string password = string.Empty;
  17. string webUrl = string.Empty;
  18. string modifiedDate = string.Empty;
  19. try {
  20. // Site Url to scan
  21. webUrl = "https://SiteUrl";
  22. using(context = new ClientContext(webUrl)) {
  23. userName = "UserName";
  24. password = "Password";
  25. foreach(char c in password.ToCharArray())
  26. pswd.AppendChar(c);
  27. // Setting credential for the above site
  28. context.Credentials = new SharePointOnlineCredentials(userName, pswd);
  29. web = context.Web;
  30. context.Load(web, w => w.ServerRelativeUrl, w => w.Id, w => w.CurrentUser);
  31. context.ExecuteQuery();
  32. // Getting list by Title
  33. list = context.Web.Lists.GetByTitle("Documents");
  34. context.Load(list, L => L.Id);
  35. // Getting all items from selected list using caml query
  36. itemCollection = list.GetItems(CamlQuery.CreateAllItemsQuery());
  37. //Loading selected list items
  38. context.Load(itemCollection, IC => IC.Include(I => I.Id, I => I.DisplayName, I => I.File, I => I.File.ServerRelativeUrl));
  39. context.ExecuteQuery();
  40. // The modified date will be changed to below date after the excuted successfully
  41. modifiedDate = "20/01/2019";
  42. // The modified user will be changed to current user after the code excuted successfully
  43. modifiedBy = web.CurrentUser;
  44. // Looping each item
  45. if (itemCollection != null && itemCollection.Count > 0) {
  46. for (int iCount = 0; iCount < itemCollection.Count; iCount++) {
  47. try {
  48. //getting individual list item from item collection
  49. item = itemCollection[iCount];
  50. var listItemFormUpdateValueColl = new List < ListItemFormUpdateValue > ();
  51. ListItemFormUpdateValue listItemFormUpdateValue = new ListItemFormUpdateValue();
  52. listItemFormUpdateValue.FieldName = "Modified";
  53. listItemFormUpdateValue.FieldValue = modifiedDate.ToString();
  54. listItemFormUpdateValueColl.Add(listItemFormUpdateValue);
  55. item["Editor"] = modifiedBy.Id;
  56. listItemFormUpdateValue = new ListItemFormUpdateValue();
  57. listItemFormUpdateValue.FieldName = "Modified_x0020_By";
  58. listItemFormUpdateValue.FieldValue = modifiedBy.Id.ToString();
  59. listItemFormUpdateValueColl.Add(listItemFormUpdateValue);
  60. // This method will update the ListItem properties without increasing file version
  61. item.ValidateUpdateListItem(listItemFormUpdateValueColl, true, "");
  62. context.ExecuteQuery();
  63. } catch (Exception ex) {}
  64. break;
  65. }
  66. }
  67. }
  68. } catch (Exception ex) {}
  69. }
  70. }
  71. }

After executing the above code, we can find that the ‘Modified User’ and ‘Modified Date’ field value is updated but the Document/File version remains the same as it was before being updated.

In the below screenshot you can verify the difference.

Before Update
Update A SharePoint Listitem Without Increasing Its Item File Version Using SharePoint Client Side Model(CSOM)
After Update
Update A SharePoint Listitem Without Increasing Its Item File Version Using SharePoint Client Side Model(CSOM)