Hi @Mj
You can use the PageIterator
class to simplify the process of consuming paged collections. The PageIterator
handles enumerating the current page and requesting subsequent pages automatically.
// Get the first page of users with a page size of 5
var users = await graphClient.Users
.GetAsync(requestConfiguration =>
{
requestConfiguration.QueryParameters.Top = 5;
requestConfiguration.QueryParameters.Select = new string[] { "id", "displayName" };
});
// Create a page iterator to iterate over all users
var pageIterator = PageIterator<User, UserCollectionResponse>
.CreatePageIterator(
graphClient,
users,
// Callback executed for each user in the collection
(user) =>
{
Console.WriteLine(user.DisplayName);
return true; // Return true to continue the iteration
});
// Start the iteration
await pageIterator.IterateAsync();
Hope this helps.
If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.