First of all ,we need to create index for columns need to be updated If you have more than 5000 items
In terms of code, we can retrieve all field Titles , then filter out the columns that need to be updated.
We can get all items which value is ‘aaaaa’ by camlQuery. Finally update them to ‘bbbbb’.
Following code as sample:
using (ClientContext clientContext = new ClientContext("https://yoururl"))
{
SecureString passWord = new SecureString();
foreach (char c in "password".ToCharArray()) passWord.AppendChar(c);
clientContext.Credentials = new SharePointOnlineCredentials("username", passWord);
Web oWebsite = clientContext.Web;
List oList = clientContext.Web.Lists.GetByTitle("Test List");
//retrieve all fields
FieldCollection oFieldCollection = oList.Fields;
clientContext.Load(oFieldCollection, oFields => oFields.Include(field => field.Title));
clientContext.ExecuteQuery();
CamlQuery camlQuery = new CamlQuery();
foreach (Field oField in oFieldCollection) {
//Filter out the fields that need to be updated
if (oField.Title == "Alpha" || oField.Title == "Beta" || oField.Title == "Charlie" || oField.Title == "delta") {
Console.WriteLine(oField.Title);
camlQuery.ViewXml = @"<View><Query><Where><Eq><FieldRef Name='" + oField.Title + "' /><Value Type='Text'>aaaaa</Value></Eq></Where></Query></View>";
ListItemCollection items = oList.GetItems(camlQuery);
clientContext.Load(items);
clientContext.ExecuteQuery();
foreach (ListItem item in items)
{
item[oField.Title] = "bbbbb";
item.Update();
clientContext.ExecuteQuery();
}
}
}
}
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.