Reputation: 1
I am attempting to create a child folder in Sharepoint and I am receiving errors. I can successfully create two levels of folders, but upon creating the third level, I receive the error below:
"The request URI is not valid. The bound function binding to 'microsoft.graph.driveItem' does not support the escape function annotation."
I am using Postman and taking the steps here to create folders:
1) Top Level: (Successful) - Folder1 Created
https://graph.microsoft.com/v1.0/sites/<SITE_ID>/drive/root/children
{
"name": "Folder1",
"folder": { },
"@microsoft.graph.conflictBehavior": "replace"
}
2) First Child (Successful - Folder2 Created within Folder1)
https://graph.microsoft.com/v1.0/sites/<SITE_ID>/drive/root:/Folder1:/children
{
"name": "Folder2",
"folder": { },
"@microsoft.graph.conflictBehavior": "replace"
}
3) Second Child (Fails)
https://graph.microsoft.com/v1.0/sites/<SITE_ID>/drive/root:/Folder1:/Folder2:/children
{
"name": "Folder3",
"folder": { },
"@microsoft.graph.conflictBehavior": "replace"
}
Any feedback how to properly create the Folder3 folder would be much appreciated.
Upvotes: 0
Views: 498
Reputation: 58
Trying using below code.
Where parentDriveId is root drive ID and driveId is the folder where we try to create folder.
var driveItem = new DriveItem
{
Name = driveName,
Folder = new Folder { },
AdditionalData = new Dictionary<string, object>()
{
{ "@microsoft.graph.conflictBehavior", "rename" }
}
};
createdDriveId = (await graphclient.Drives[parentDriveId].Items[driveId].Children.Request().AddAsync(driveItem)).Id;
Upvotes: 0
Reputation: 59318
In the last example, the error occurs since invalid Url format is specified for accessing Folder2
in the provided endpoint:
https://graph.microsoft.com/v1.0/sites/<SITE_ID>/drive/root:/Folder1:/Folder2:/children
|_________________|
^^^
invalid path syntax for accessing Folder2
To create folder under Folder2
sub folder, the Url format should be as follows:
https://graph.microsoft.com/v1.0/sites/<SITE_ID>/drive/root:/Folder1/Folder2:/children
Refer Addressing resources in a drive on OneDrive for a more details.
Upvotes: 1