使用Graph SDK在Sharepoint Drive中的特定目录中创建文件夹

问题描述 投票:0回答:1

如何仅使用给定的网址使它成为现实,idk是否可能?

我想做什么:

根据字符串在驱动器中的特定位置创建文件夹。此字符串由3个部分组成(每个部分都表示文件夹容易!)例如,mystring =“ Analyse_General_Theory”,云端硬盘中的路径应类似于:分析/一般/理论

so:

我对解决方案的想象就像这样:)

将我的stringUrl传递给构建请求,然后发布我的文件夹

stringUrl = "https://CompanyDomin.sharepoint.com/sites/mySite/SharedFolders/Analyse/General/Theory"

然后

await graphClient.Request(stringUrl).PostAsync(myLastFolder) !!! 

所以会是结果!

分析/常规/理论/ myLastFolder

有这样的东西吗?还是类似于这种方法?

c# azure-ad-graph-api microsoft-graph-files
1个回答
0
投票

如果要使用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

例如

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"
}

关于如何使用SDK实现,请参考以下步骤

  1. Register Azure AD application

  2. Create a client secret

  3. 为应用程序添加API权限。请添加应用程序权限:Files.ReadWrite.AllSites.ReadWrite.All

  4. 代码。我使用客户端凭证流。

/* 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);

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.