An API that connects multiple Microsoft services, enabling data access and automation across platforms
To create a folder directly under the root of a drive with the Microsoft Graph SDK, the request must target the drive’s root item correctly. The invalid request comes from using Items["root"], which expects an item ID, not the literal string "root".
Use the Root navigation or the /root/children pattern instead of Items["root"].
For example, the REST call to create a folder in the signed-in user’s OneDrive root is:
POST https://graph.microsoft.com/v1.0/me/drive/root/children
Content-Type: application/json
{
"name": "New Folder",
"folder": { },
"@microsoft.graph.conflictBehavior": "fail"
}
The equivalent SDK pattern is (conceptually):
var driveItem = new DriveItem
{
Name = PrepareDriveItemName(dossierName).Trim(),
Folder = new Microsoft.Graph.Models.Folder(),
AdditionalData = new Dictionary<string, object>
{
{ "@microsoft.graph.conflictBehavior", "fail" },
},
};
// For the current user’s default drive root
var addedDriveItem = await graphClient
.Me
.Drive
.Root
.Children
.PostAsync(driveItem);
// Or, for a specific drive by ID
var addedDriveItem2 = await graphClient
.Drives[clientRootDriveId]
.Root
.Children
.PostAsync(driveItem);
Key points:
- Do not use
Items["root"]when the SDK expects an item ID. - To create under root, use:
-
Me.Drive.Root.Children.PostAsync(...), or -
Drives[drive-id].Root.Children.PostAsync(...).
-
- Ensure the app has at least
Files.ReadWrite(delegated) orFiles.ReadWrite.All(application) permissions as documented fordriveItem-post-children.
If creating under a subfolder instead of root, use the parent folder’s item-id:
var addedDriveItem = await graphClient
.Drives[clientRootDriveId]
.Items[parentItemId]
.Children
.PostAsync(driveItem);
This matches the documented POST /drives/{drive-id}/items/{parent-item-id}/children pattern.
References: