Skip to main content

Command Palette

Search for a command to run...

Access a OneDrive root folder with Microsoft Graph

Updated
3 min read
Access a OneDrive root folder with Microsoft Graph
R

I'm a .NET/M365 developer, trainer, author, MVP & MCT Alumni

When working with files in OneDrive through the Microsoft Graph, a common task is retrieving the root folder of a drive. This post shows how to access the root folder using a drive ID using the Graph REST API and the C# Graph SDK.

Microsoft Graph exposes OneDrive using two key resources: Drive and DriveItem. Drive represents the logical container (a user’s OneDrive or a SharePoint document library), while DriveItem represents an item within that drive — including the root.

Prerequisites

To access a drive’s root folder, you need:

  • A valid access token (delegated or application)

  • Permission to read or write files

  • The driveId of the target drive (if using the driveId approach)

Microsoft Graph and OneDrive use OAuth 2.0 for authorization, and each API call requires sending the token in the Authorization header.

Tip: If you don't have a driveId, you can reach a drive's root through several alternative paths: /me/drive/root for the signed-in user, /users/{user-id}/drive for a specific user, and /groups/{group-id}/drive for a group or team site.

Graph REST API

To get the root folder of a drive, make a GET request to:

GET https://graph.microsoft.com/v1.0/drives/{drive-id}/root

To get the items in the root folder, make a GET request to:

GET https://graph.microsoft.com/v1.0/drives/{drive-id}/root/children

These two endpoints mirror each other cleanly: /root for the folder, /root/children for its contents.

C# Graph SDK

To get the root folder of the OneDrive using the C# Graph SDK, you would write code like this:

var root = await graphClient.Drives[{drive-id}]
    .Root
    .GetAsync();

So far this matches the documentation so it should not be a source of confusion. However, this changes when you try to list the items in the root folder using the Graph SDK. You might think, based on the above, the Graph documentation and online code samples, that you would use code like this:

var root = await graphClient.Drives[{drive-id}]
    .Root
    .Children
    .GetAsync();

But this gives a compile time error stating that:

'RootRequestBuilder' does not contain a definition for 'Children'...

It turns out you instead need to use .Items["root"] instead of .Root to get things to work.

var root = await graphClient.Drives[{drive-id}]
    .Items["root"]
    .Children
    .GetAsync();

Treating the root as "the item whose ID is root" unlocks the full set of DriveItem navigations, including Children. This behavior isn't clearly called out in the Graph SDK documentation as of this writing, which is what makes it so easy to get stuck on.