How to update Created, Created By, Modified and Modified By in list items using CSOM?
1 Answer
Please find the code to update Created, Created By, Modified, Modified By using CSOM.
ClientContext ctx = new ClientContext("http://siteURL/");
List list = ctx.Web.Lists.GetByTitle("Info Path");
ListItemCollection items = list.GetItems(CamlQuery.CreateAllItemsQuery());
ctx.Load(items); // loading all the fields
ctx.ExecuteQuery();
User theUser = ctx.Web.EnsureUser("domain\\user");
ctx.Load(theUser);
ctx.ExecuteQuery();
foreach (var item in items)
{
item["Created"] = "2015-07-03";
item["Modified"] = "2017-07-03";
item["Editor"] = theUser;
item["Author"] = theUser;
item.Update(); //Apply the change
}
ctx.ExecuteQuery();
-
3i too agree with the code given above, but it adds an version to the item if we update the system columns– PradeepApr 24, 2018 at 11:44
-
I couldn't make it work. As soon as ExecuteQuery is executed, the "Created" / "Modified" values revert to their previous values. On another hand, the versioning can be suppressed using List.EnableVersioning (followed by List.Update and ClientContext.ExecuteQuery). Mar 8, 2019 at 13:32
-
You can avoid the extra versions by using
item.SystemUpdate()
instead ofitem.Update()
- this may not have been available in CSOM when the question was raised (can't remember when it was added). Mar 27, 2019 at 16:34