As per the specs, we can get a maximum of 200 item when we retrieve the list of files and folders from OneDrive(Personal or Business) along with the NextPageLink. However, I also need to get the total count of files available while getting the list of files and folders from:
1.) Root
2.) Shared With Me
3.) Inside the DriveItem
4.) Search
How can I achieve this?
When I make the below calls using Microsoft Graph SDK, I get "Count" field which returns the count of items in the returned list:
var response = await client.Me.Drive.Root.Children.Request().GetAsync();
var sharedWithMe = await client.Me.Drive.SharedWithMe().Request().GetAsync();
However, I also need the total count of items to be displayed. Is this possible?
There isn't a way to get a total number of items when getting a list of files/folders from all of those sources.
You can make a request to the /drive/root object, which will return the number of items contained directly under the root:
GET https://graph.microsoft.com/v1.0/me/drive/root
{
"name": "root",
"folder": {
"childCount": 7
},
"root": {},
"size": 51242712
}
Truncated result, but you can see that there are 7 items from folder.childCount == 7. This property is available on any folder, so if you are enumerating through the contents of a folder, you can query the folder itself to get an approximate item count (it's possible the count can change while you are paging through items in the folder).
We don't have anything available for Shared With Me or Search results today. OneDrive personal returns an approximate count of items for search results when using search with the api.onedrive.com endpoint, but this isn't (yet) available in Microsoft Graph or for OneDrive for Business.