Jan 17 2017 03:30 AM
Hi Everyone,
I hope someone can help me out :)
I have a list with more than 5000 items on Sharepoint Online Site. Before the list reached 5000 items, I've used the following snippet to get all items:
var camlquery = new CamlQuery(); camlquery.ViewXml = @"<View Scope='RecursiveAll'> <ViewFields> <FieldRef Name='OppId' /> </ViewFields> <Query> <QueryOptions> <ViewAttributes Scope='Recursive' /> </QueryOptions> </Query> </View>"; ListItemCollection listItems = _currentList.GetItems(camlquery); _clientContext.Load(listItems, items => items.Include(item => item["OppId"], item => item.Id)); _clientContext.ExecuteQuery();
Now I got in this nasty situation where I have more than 5000 items. Normally this is not an problem. I've managed it before in powershell by paging through the results.
In this case I'm using Microsoft.SharePoint.Client.ListItemCollection and add items to the collection with the function GetItems(camlquery). When I try adding additional items from another 'page' it seems not to work.
I tried to loop through the items and add these to the ListItemCollection. But there is no Add or Insert function available.
foreach (ListItem myListItem in listItems2) { listItems.Add(myListItem); }
I need to return one ListItemCollection with more than 5000 items.
Thanks for helping!
I've also posted this question on StackOverflow
Jan 18 2017 05:22 AM
SolutionI've found a way to get all items by using IList<ListItem> to collect all the objects of type ListItem from the ListItemCollection.
IList<ListItem> listItemsAll = new List<ListItem>(); // Loop through pages of list items //... Getting all items foreach (ListItem myListItem in listItems) { listItemsAll.Add(myListItem); } // End Loop return listItemsAll;
In this case I return a List but I only needed to change the type of list from ListItemCollection to IList<ListItem>. Everythings works as expected.
May 23 2020 12:35 PM
@Bernd Verhofstadt - Can you please share the one you did using CSOM PowerShell to read the lists having more than 5000 items in it.
Jan 18 2017 05:22 AM
SolutionI've found a way to get all items by using IList<ListItem> to collect all the objects of type ListItem from the ListItemCollection.
IList<ListItem> listItemsAll = new List<ListItem>(); // Loop through pages of list items //... Getting all items foreach (ListItem myListItem in listItems) { listItemsAll.Add(myListItem); } // End Loop return listItemsAll;
In this case I return a List but I only needed to change the type of list from ListItemCollection to IList<ListItem>. Everythings works as expected.