Reputation: 737
As it is documented, using the Microsoft Graph REST API you can (among other options) get an item by Id or Path. This works fine, as expected:
GET /me/drive/items/{item-id}/children
GET /me/drive/root:/{item-path}:/children
Using the .NET SDK, I can get a folder by Id (i.e. the first case):
var items = await graphClient.Me.Drive.Items[myFolderId].Children.Request().GetAsync();
However, I couldn't find how (using the .NET SDK) to do the same, but specifying a path instead of an Id (i.e. the second case).
I don't want to find an Id of a path I already know, to create the request for it. Right?
I'm afraid is not possible to do this using the current SDK (Microsoft Graph Client Library 1.1.1)?
Upvotes: 13
Views: 16929
Reputation: 915
For version 5 I did the following:
results = await graphClient
.Drives["{ENTER_DRIVE_ID_HERE}"]
.Root
.ItemWithPath("{PATH_YOU_CARE_ABOUT}")
.Children
.GetAsync();
In my use case I needed to iterate over all files in a given folder on a shared drive. I can't remember how I found the drive id but I used the Graph Explorer to find it.
Upvotes: 5
Reputation: 176
In order to use the Microsoft Graph SDK with Office365 for Business/Sharepoint/Teams, replace the "Me" in the code with "Groups[teamId/groupId]".
Like this:
var items = await graphClient.Groups["teamId/groupId"].Drive.Root
.ItemWithPath("/this/is/the/path").Children.Request().GetAsync();
If you use the Microsoft Graph Explorer, you can find out your Team/Group Id: https://developer.microsoft.com/en-us/graph/graph-explorer
Upvotes: 1
Reputation: 737
This is how:
var items = await graphClient.Me.Drive.Root
.ItemWithPath("/this/is/the/path").Children.Request().GetAsync();
Use just the plain path. Don't include the ":", and don't include the "/drive/root:/".
it was obvious, now that I see it...
Upvotes: 18