Update string in SharePoint online List

Power Platform Resource 1 Reputation point
2021-06-08T22:29:22.287+00:00

Hi,

I have SharePoint online list with more than 5000 entries. In couple of columns I need to update string 'aaaaaa' to 'bbbbb'. Any idea how to do this? Any help would be greatly appreciated.

Thank you.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,230 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,569 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,431 Reputation points Microsoft External Staff
    2021-06-09T10:10:58.24+00:00

    Hi @Power Platform Resource ,

    First of all ,we need to create index for columns need to be updated If you have more than 5000 items
    103827-image.png

    103817-image.png
    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.