I know this is simple but for the life of me I can't figure it out.
I'm trying to load a list of users from an Azure AD Group using the graph api. I'm almost there. I can successfully call the API, get the right group, and even see the members. But when I load that list in a list, all i see is a list of Microsoft.Graph.User. If inspect the list in code, I can drill down and see the display names but I don't know how to access them via code. there is no .displayname within the user object. Below is the code I have:
GraphServiceClient graphClient = await Authentication.SignInAndInitGraph(scope);
List<User> users = new List<User>();
var members = await graphClient.Groups["GroupID"].Members
.Request()
.GetAsync();
users.AddRange(members.CurrentPage.OfType<User>());
while(members.NextPageRequest != null)
{
members = await members.NextPageRequest.GetAsync();
users.AddRange(members.CurrentPage.OfType<User>());
}
lstUsers.DataSource = users;
What am I missing?
CodePudding user response:
Convert members to list.
var members = await graphClient.Groups["group_id"].Members.Request().GetAsync();
var list = members.ToList();
foreach (Microsoft.Graph.User user in list) {
var name = user.DisplayName;
}

