0

I have an SP list of items, each item has a unique Title. I would like to use the title as my way to find and then update that row of data. I thought the below code would find only the item that has a Title = "Apptest" but it always gives me all items in the list and all of them are updated. I get the same results if I remove the ViewXml line, so I think there is something wrong with that line but I can't find it. Before: Before running code After:After running the code

var list = clientContext.Web.Lists.GetByTitle("Test");
            var camlQuery = new CamlQuery
            {
                ViewXml = @"<Query><Where><Eq><FieldRef Name='Title' /><Value Type='Text'>Apptest</Value></Eq></Where></Query>"
            };

            var listItems = list.GetItems(camlQuery);
            clientContext.Load(listItems);
            clientContext.ExecuteQuery();

            foreach (var listItem in listItems)
            {
                Console.WriteLine($"{listItem["Title"]}");
                listItem["Title"] = "AppUpdateTest";
                listItem.Update();
                clientContext.ExecuteQuery();
            }
0

Please have a try to add 'View' around 'Query' like below:

{ ViewXml = "<View><Query><Where><Eq><FieldRef Name='Title' /><Value Type='Text'>xxxxx</Value></Eq></Where></Query></View>"};

Reference docs:

1
  • Thanks! I figured it would be something simple. – David Watkins Jun 1 '20 at 11:46

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.