提问人:Alexey Litvin 提问时间:11/16/2023 更新时间:11/16/2023 访问量:5
Microsoft Graph net sdk v5 SiteWithPath
Microsoft Graph net sdk v5 SiteWithPath
问:
以前,我有以下代码来获取基于 sharepoint 链接的驱动器项
var teamSiteName = "TEAM_NAME";
var relativeFolderPath = "Shared%20Documents/Channel%20to%20sync/DocumentTree";
Drive rootTeamDrive = await graphServiceClient.Sites.Root.SiteWithPath($"sites/{teamsSiteName}").Drive.Request().GetAsync();
DriveItem folder = await graphServiceClient
.Drives[rootTeamDrive.Id]
.Root
.ItemWithPath(relativeFolderPath)
.Request()
.GetAsync();
答:
0赞
Alexey Litvin
11/16/2023
#1
根据这里的答案 https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/1693 我创建了更具可读性的解决方案
但是我需要添加Sites.Read.All权限。
使用正则表达式,我把它吐成三个变量
var hostname = "DOMAIN.sharepoint.com";
var teamSiteName = "TEAM_NAME";
var relativeFolderPath = "Shared%20Documents/Channel%20to%20sync/DocumentTree";
这是我的代码
var path = $"/sites/{teamsSiteName}";
var site = await graphServiceClient.Sites[$"{hostname}:{path}"].GetAsync((requestConfiguration =>
{
requestConfiguration.QueryParameters.Expand = new string[] { nameof(Site.Drive) };
}));
DriveItem folder = await graphServiceClient
.Drives[site.Drive.Id]
.Root
.ItemWithPath(relativeFolderPath)
.GetAsync();
评论