Это ожидаемое поведение, поскольку конечная точка GET https://graph.microsoft.com/v1.0/me/drive/root/children
возвращает только один уровень под элементами, поэтому для извлечения всех элементов необходимо явно извлечь элементы подпапки, как показано ниже:
var allItems = new List<DriveItem>();
await GetAllChildren(graphClient.Me.Drive, allItems);
foreach (var item in allItems)
{
Console.WriteLine(item.Name);
}
где
static async Task GetAllChildren(IDriveRequestBuilder drive,List<DriveItem> result, IDriveItemRequestBuilder root = null)
{
root = root ?? drive.Root;
var items = await root.Children.Request().GetAsync();
result.AddRange(items.ToList());
foreach (var item in items)
{
if (item.Folder != null && item.Folder.ChildCount > 0)
{
await GetAllChildren(drive, result, drive.Items[item.Id]);
}
}
}
Опция 2
Существует лучший способ (с точки зрения производительности) получить все метаданные элементов диска через следующую конечную точку:
GET https://graph.microsoft.com/v1.0/me/drive/list/items?$expand=driveItem
Примечание. Для извлечения всех элементов требуется только один запрос, что может быть большим преимуществом по сравнению с предыдущим подходом
Пример
var allItems = await graphClient.Me.Drive.List.Items.Request().Expand( i => i.DriveItem).GetAsync();
foreach (var item in allItems)
{
Console.WriteLine(item.DriveItem.Name); //print name
}