Hello @Meir Rotfleisch , The PageIterator class simplifies consuming of paged collections. PageIterator handles enumerating the current page and requesting subsequent pages automatically. Here is the documentation for your reference :https://learn.microsoft.com/en-us/graph/sdks/paging?tabs=csharp
var messages = await graphClient.Me.Messages
.Request()
.Header("Prefer", "outlook.body-content-type=\"text\"")
.Select(e => new {
e.Sender,
e.Subject,
e.Body
})
.Top(10)
.GetAsync();
var pageIterator = PageIterator<Message>
.CreatePageIterator(
graphClient,
messages,
// Callback executed for each item in
// the collection
(m) =>
{
Console.WriteLine(m.Subject);
return true;
},
// Used to configure subsequent page
// requests
(req) =>
{
// Re-add the header to subsequent requests
req.Header("Prefer", "outlook.body-content-type=\"text\"");
return req;
}
);
await pageIterator.IterateAsync();
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
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.