3

I am getting a "Version conflict" error while trying to update a list item via CSOM.

Code:

            String webUrl = <Your Weburl>; 
                    String path = row["Path"].ToString();
                    String listTitle = null;


                    try
                    {
                        using (ClientContext ctx = new ClientContext(webUrl))
                        {
                            ctx.Credentials = new SharePointOnlineCredentials(tenantsitelogin, password);
                            listTitle = "Pages"; // path.Substring(0, path.LastIndexOf("/")).Substring(webUrl.Length + 1);
                            var list = ctx.Web.Lists.GetByTitle(listTitle);
                            var listItem = list.GetItemById(184);
                            ctx.Load(list);
                            ctx.Load(listItem, i => i.File);
                            var file = listItem.File;
                            ctx.Load(file, x => x.Versions);
                            ctx.ExecuteQuery();

                            file.UnPublish("Some Comment");
                            listItem.Update();
                            ctx.ExecuteQuery();

                            //ctx.Web.Lists.GetByTitle(listTitle);
                        }
                    }

Need to resolve the "Version conflict" error.

Subhadip Dhar
  • 31
  • 1
  • 5

1 Answers1

1

Remove following line from your code to resolve “Version conflict.” error

listItem.Update();