Microsoft Graph API 客户端库 - 创建一个文件夹
Microsoft Graph API client library - create a folder
我正在尝试使用 Microsoft Graph (C# SDK) 在 SharePoint 中的现有文件夹下创建一个文件夹。我知道在 SharePoint 或 OneDrive 上创建文件夹在使用 Graph API 时应该是相同的,但我仍然找不到任何好的在线参考。我找到的唯一一篇文章是 an old one,它在 JavaScript.
中只有一个例子
我有一个根文件夹 A
,我想在 A
下创建一个子文件夹 B
。
代码如下:
var driveRequestBuilder = graphClient
.Sites[SharePointSiteId]
.Lists[ListId]
.Drive;
var folderRequestBuilder = driveRequestBuilder
.Root
.ItemWithPath("A");
var folderDriveItem = folderRequestBuilder
.Request()
.GetAsync()
.Result; // This returns the root folder "A"'s info
var subFolderDriveItem = new DriveItem()
{
Name = "B",
Folder = folderDriveItem.Folder
};
var result = folderRequestBuilder
.Request()
.CreateAsync(subFolderDriveItem)
.Result;
最后一行代码抛出一个AggregateException
(因为TPL),其中包含内部异常:
Code: -1, Microsoft.SharePoint.Client.InvalidClientQueryException
Message: The parameter folder does not exist in method getByPath.
Inner error
我想知道创建子文件夹的正确语法。
如果是子文件夹,则创建文件夹的端点应为
POST https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/drive/root:/{path}:/children
Content-Type: application/json
{
"name": "New folder name",
"folder": { },
"@microsoft.graph.conflictBehavior": "rename"
}
msgraph-sdk-dotnet
示例:
var folder = new DriveItem
{
Name = "<sub folder name>",
Folder = new Folder()
};
var result = await graphClient
.Sites[siteId]
.Lists[listId]
.Drive
.Root
.ItemWithPath("<folder path>")
.Children
.Request()
.AddAsync(folder);
我正在尝试使用 Microsoft Graph (C# SDK) 在 SharePoint 中的现有文件夹下创建一个文件夹。我知道在 SharePoint 或 OneDrive 上创建文件夹在使用 Graph API 时应该是相同的,但我仍然找不到任何好的在线参考。我找到的唯一一篇文章是 an old one,它在 JavaScript.
中只有一个例子我有一个根文件夹 A
,我想在 A
下创建一个子文件夹 B
。
代码如下:
var driveRequestBuilder = graphClient
.Sites[SharePointSiteId]
.Lists[ListId]
.Drive;
var folderRequestBuilder = driveRequestBuilder
.Root
.ItemWithPath("A");
var folderDriveItem = folderRequestBuilder
.Request()
.GetAsync()
.Result; // This returns the root folder "A"'s info
var subFolderDriveItem = new DriveItem()
{
Name = "B",
Folder = folderDriveItem.Folder
};
var result = folderRequestBuilder
.Request()
.CreateAsync(subFolderDriveItem)
.Result;
最后一行代码抛出一个AggregateException
(因为TPL),其中包含内部异常:
Code: -1, Microsoft.SharePoint.Client.InvalidClientQueryException
Message: The parameter folder does not exist in method getByPath.
Inner error
我想知道创建子文件夹的正确语法。
如果是子文件夹,则创建文件夹的端点应为
POST https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/drive/root:/{path}:/children
Content-Type: application/json
{
"name": "New folder name",
"folder": { },
"@microsoft.graph.conflictBehavior": "rename"
}
msgraph-sdk-dotnet
示例:
var folder = new DriveItem
{
Name = "<sub folder name>",
Folder = new Folder()
};
var result = await graphClient
.Sites[siteId]
.Lists[listId]
.Drive
.Root
.ItemWithPath("<folder path>")
.Children
.Request()
.AddAsync(folder);