I am getting the the groups based on users from Microsoft Graph Api. Although I am getting the groups but they are coming to total count of 100.
I tried to use paging technique but it is keep failing. Can someone help me out?
var page = graphClient
.Users[uniqueIdentification]
.MemberOf
.Request()
.GetAsync().Result;
var names = new List<string>();
names.AddRange(page
.OfType<Group>()
.Select(x => x.DisplayName)
.Where(name => !string.IsNullOrEmpty(name)));
The above code only return top 100.
When I tried below code for paging it got cast error .
Error:
Unable to cast object of type 'System.Collections.Generic.List`1[Microsoft.Graph.DirectoryObject]' to type 'System.Collections.Generic.IEnumerable`1[Microsoft.Graph.Group]'.
Code:
var group2 = new List<Group>();
var groupsPage = graphClient.Users[uniqueIdentification].MemberOf.Request().Top(300).GetAsync().Result;
group2.AddRange((IEnumerable<Group>)groupsPage.CurrentPage);
while (groupsPage.NextPageRequest != null)
{
groupsPage = groupsPage.NextPageRequest.GetAsync().Result;
group2.AddRange((IEnumerable<Group>)groupsPage.CurrentPage);
}