admin管理员组文章数量:1388068
How to create a new folder in root of some One Drive via Microsoft Graph SDK for C#?
Documentation suggests to use HTTP post request to "me/drive/root/children" or "/drives/{drive-id}/root/children". But Root request builder does not have Children collection, so the code can not be compiled:
await client.Drives[someDriveId].Root.Children.PostAsync(newFolderItem);
Is it safe to use ItemWithPath("/")
for this case?
await client.Drives[someDriveId].Root.ItemWithPath("/").Children.PostAsync(newFolderItem)
Update: How this question has appeared. I'm updating the code from using MsGraph C# SDK 4.x to MsGraph C# SDK 5.x and found that Root
doesn't contain Children
property anymore.
P.S.:
How to create a new folder in root of some One Drive via Microsoft Graph SDK for C#?
Documentation suggests to use HTTP post request to "me/drive/root/children" or "/drives/{drive-id}/root/children". But Root request builder does not have Children collection, so the code can not be compiled:
await client.Drives[someDriveId].Root.Children.PostAsync(newFolderItem);
Is it safe to use ItemWithPath("/")
for this case?
await client.Drives[someDriveId].Root.ItemWithPath("/").Children.PostAsync(newFolderItem)
Update: How this question has appeared. I'm updating the code from using MsGraph C# SDK 4.x to MsGraph C# SDK 5.x and found that Root
doesn't contain Children
property anymore.
P.S.: https://github/microsoftgraph/msgraph-sdk-dotnet/discussions/2864
Share Improve this question edited Mar 17 at 14:08 23W asked Mar 17 at 10:40 23W23W 1,54022 silver badges47 bronze badges 6 | Show 1 more comment1 Answer
Reset to default 1Instead of .Root
, you can use .Items["root"]
. The latter has a Children
property. This is called out in the documentation on listing the children of a drive item.
Here's an example:
var requestBody = new DriveItem
{
Name = "Folder C",
Folder = new Folder
{
},
AdditionalData = new Dictionary<string, object>
{
{
"@microsoft.graph.conflictBehavior" , "rename"
},
},
};
var item = await graphClient.Drives[driveId]
.Items["root"]
.Children
.PostAsync(requestBody);
本文标签: azureHow to create a new folder in Drive root via MsGraph SDK for CStack Overflow
版权声明:本文标题:azure - How to create a new folder in Drive root via MsGraph SDK for C#? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744566558a2613084.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
client.Drives[someDriveId].Root.Children
can not be compiled because Root request builder does not contain Children property. – 23W Commented Mar 17 at 11:02await client.Drives[someDriveId].Root.Children.PostAsync(newFolderItem);
So as a workaround useItemWithPath("/")
directly targets the root of the OneDrive. – Pratik Jadhav Commented Mar 17 at 11:09