I'm retrieving drive items from the default document library of multiple SharePoint Online sites. I need, among other things, the user information in the CreatedBy.User
property.
For some sites, I can just access that property without any issue, but for one site the code crashes because the property is null. Coincidentally, this happens on the site with the most drive items.
These are the relevant code sections.
var items = await GetChildren(_client.Sites[siteId].Drive.Root.Children).ToListAsync();
private static async IAsyncEnumerable<DriveItem> GetChildren(IDriveItemChildrenCollectionRequestBuilder builder)
{
var page = builder.Request()
.Expand(d => d.ListItem)
.GetAsync().Result;
foreach (var driveItem in page)
{
yield return driveItem;
}
while (page.NextPageRequest is not null)
{
page = await page.NextPageRequest.GetAsync();
foreach (var driveItem in page)
{
yield return driveItem;
}
}
}
How can I force the request to always include the CreatedBy.User
information? When I additionally request that specific property it does work, but doing so many separate calls is not really an option. There are just too many items in that document library.