Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Version conflict." error while trying to update list item via CSOM

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.

like image 859
Subhadip Dhar Avatar asked Dec 07 '25 08:12

Subhadip Dhar


1 Answers

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

listItem.Update();
like image 161
Rafał Milewski Avatar answered Dec 08 '25 23:12

Rafał Milewski