4

How to update Created, Created By, Modified and Modified By in list items using CSOM?

6

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();
  • 3
    i too agree with the code given above, but it adds an version to the item if we update the system columns – Pradeep Apr 24 '18 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). – Yet Another Code Maker Mar 8 at 13:32
  • You can avoid the extra versions by using item.SystemUpdate() instead of item.Update() - this may not have been available in CSOM when the question was raised (can't remember when it was added). – randomsock Mar 27 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.