Has*_*man 2 c# azure-ad-graph-api microsoft-graph-files
如何仅使用给定的 Url 使其成为现实,以及是否可能,idk?
我正在尝试做什么:
根据字符串在驱动器中的特定位置创建文件夹。
该字符串由 3 部分组成(每个部分代表文件夹简单!)例如, mystring = "Analyse_General_Theory" ,驱动器中的路径应类似于:Analyse/General/Theory
所以 :
我的解决方案的想象力就是这样:)
将我的 stringUrl 传递给构建请求,然后发布我的文件夹
stringUrl = "https://CompanyDomin.sharepoint.com/sites/mySite/SharedFolders/Analyse/General/Theory"
Run Code Online (Sandbox Code Playgroud)
然后
await graphClient.Request(stringUrl).PostAsync(myLastFolder) !!!
Run Code Online (Sandbox Code Playgroud)
所以才会有这样的结果!
分析/一般/理论/myLastFolder
有这样的东西吗?或者可能类似于这种方法?
如果您想使用 Graph API 在 SharePoint 中创建文件夹,请使用以下Microsoft graph Rest API。因为Azure AD图形API只能用于管理Azure AD资源(例如用户、组等),不能用于管理SharePoint资源。如果我们想使用Graph API管理SharePoint资源,我们需要使用Microsoft Graph API
POST https://graph.microsoft.com/v1.0/sites/{site-id}/drive/items/{parent-item-id}/children
Run Code Online (Sandbox Code Playgroud)
例如
POST https://graph.microsoft.com/v1.0/sites/CompanyDomin.sharepoint.com/drive/items/root:/
{folder path}:/children
{
"name": "<the new folder name>",
"folder": { },
"@microsoft.graph.conflictBehavior": "rename"
}
Run Code Online (Sandbox Code Playgroud)
如何使用SDK实现,请参考以下步骤
为应用程序添加API权限。请添加应用程序权限:Files.ReadWrite.All和Sites.ReadWrite.All。
代码。我使用客户端凭证流。
/* please run the following command install sdk Microsoft.Graph and Microsoft.Graph.Auth
Install-Package Microsoft.Graph
Install-Package Microsoft.Graph.Auth -IncludePrerelease
*/
string clientId = "<your AD app client id>";
string clientSecret = "<your AD app client secret>";
string tenantId = "<your AD tenant domain>";
IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithTenantId(tenantId)
.WithClientSecret(clientSecret)
.Build();
ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
var item = new DriveItem
{
Name = "myLastFolder",
Folder= new Folder { },
AdditionalData = new Dictionary<string, object>()
{
{"@microsoft.graph.conflictBehavior","rename"}
}
};
var r = await graphClient.Sites["<CompanyDomin>.sharepoint.com"].Drive.Items["root:/Analyse/General/Theory:"].Children.Request().AddAsync(item);
Console.WriteLine("the folder name : " + r.Name);
Run Code Online (Sandbox Code Playgroud)