【问题标题】:Create and Manage Sharepoint DocumentSet with MS Graph使用 MS Graph 创建和管理 Sharepoint DocumentSet
【发布时间】:2021-05-22 15:12:30
【问题描述】:

我找不到使用 MS 图形在 Sharepoint 库中创建文档集的任何方法。有没有办法做到这一点?任何帮助都非常感谢

【问题讨论】:

    标签: c# .net sharepoint microsoft-graph-api


    【解决方案1】:

    AFAIK,今天没有直接的 API 可以用来实现这一点。 话虽如此,你可以试试这个锻炼,看看是否有帮助 -

    1. 获取文档库的驱动器 ID。

    获取https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${listId}?$expand=drive

    1. 创建文件夹。

    发布https://graph.microsoft.com/v1.0/drives/${library.drive.id}/root/children

    请求正文

    {
        "name": "New Folder name",
        "folder": {},
        "@microsoft.graph.conflictBehavior": "rename"
    }
    
    1. 获取已创建文件夹的 SharePoint 项 ID。

    获取https://graph.microsoft.com/v1.0/sites/${siteId}/drives/${library.drive.id}/items/${folder.id}?expand=sharepointids

    4.更新文档库中的项目,使其更新为所需的文档集。

    补丁https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${listId}/items/${sharepointIds.listItemId}

    请求正文

    {
      "contentType": {
        "id": "content-type-id-of-the-document-set"
      },
      "fields": {
        //fields that you wish to set
      }
    }
    

    【讨论】:

      【解决方案2】:

      我能够通过以下方式完成此操作,抱歉没有更新eariler:

      变量:

       SpURL = "site.sharepoint.com";
       SiteURL = "/sites/myTestSite";
       LibraryName = "Library";
       ContentType = "mycontenttype";
      

      1- 按路径获取站点 ID:

      var scopes = new string[] { ISD.MicrosoftGraph.Constants.ScopeDefault };
      var client = GraphServiceClientFactory.GetAuthenticatedGraphClient(() => AcquireAppToken(scopes), "https://graph.microsoft.com/beta");
      var site = await client.Sites.GetByPath(siteURL, spURL).Request().GetAsync();
      return site.Id;
      

      2- 按路径的驱动器 ID:

      var scopes = new string[] { ISD.MicrosoftGraph.Constants.ScopeDefault };
      var client = GraphServiceClientFactory.GetAuthenticatedGraphClient(() => AcquireAppToken(scopes), "https://graph.microsoft.com/beta");
      var request = client.Sites[siteID].Drives.Request();
      var result = await request.GetAsync();
      //.Filter is not working here for some reasone
      var filter = result?.Where(x => x.Name.Contains(LibraryName)).ToList();
      if (filter.Count > 0) {
         return filter.First().Id;
      }
      else {
         return "";
      }
      

      3- 获取列表 ID:

      var scopes = new string[] { ISD.MicrosoftGraph.Constants.ScopeDefault };
      var client = GraphServiceClientFactory.GetAuthenticatedGraphClient(() => AcquireAppToken(scopes), "https://graph.microsoft.com/beta");
      
      var request = client.Sites[siteID].Lists.Request().Filter($"displayName eq '{ListName}'");
      var result = await request.GetAsync();
      return result.First().Id;
      
      1. 列表 ID:
      var scopes = new string[] { ISD.MicrosoftGraph.Constants.ScopeDefault };
      var client = GraphServiceClientFactory.GetAuthenticatedGraphClient(() => AcquireAppToken(scopes), "https://graph.microsoft.com/beta");
      var request = client.Sites[siteID].Lists.Request().Filter($"displayName eq '{ListName}'");
      var result = await request.GetAsync();return result.First().Id;
      
      1. 添加新文件夹:
      var scopes = new string[] { ISD.MicrosoftGraph.Constants.ScopeDefault };
      var client = GraphServiceClientFactory.GetAuthenticatedGraphClient(() => AcquireAppToken(scopes), "https://graph.microsoft.com/beta");
      var folder = new DriveItem
      {
          Name = foldername,
          Folder = new Microsoft.Graph.Folder(),
          AdditionalData = new Dictionary<string, object>()
          {
              {"@microsoft.graph.conflictBehavior", "rename"}
          },
         
      };
      var folderObj = await client.Drives[driveID].Root.Children.Request().AddAsync(folder);
      return folderObj.Id;
      
      //Save folderID from the above return
      
      1. 内容类型 ID:
      var scopes = new string[] { ISD.MicrosoftGraph.Constants.ScopeDefault };
      var client = GraphServiceClientFactory.GetAuthenticatedGraphClient(() => AcquireAppToken(scopes), "https://graph.microsoft.com/beta");
      
      var request = client.Sites[siteID].Lists[listID].ContentTypes.Request().Filter($"name eq '{contentTypeName}'");
      var result = await request.GetAsync();
      return result.First().Id;
      
      1. 列表项 ID:
      var scopes = new string[] { ISD.MicrosoftGraph.Constants.ScopeDefault };
      var client = GraphServiceClientFactory.GetAuthenticatedGraphClient(() => AcquireAppToken(scopes), "https://graph.microsoft.com/beta");
      
      var request = client.Sites[siteID].Drives[driveID].Items[folderID].Request().Select("sharepointIds");
      var result = await request.GetAsync();
      return result.SharepointIds.ListItemId;
      
      1. 设置文件夹内容类型和属性:
      var scopes = new string[] { ISD.MicrosoftGraph.Constants.ScopeDefault };
      var client = GraphServiceClientFactory.GetAuthenticatedGraphClient(() => AcquireAppToken(scopes), "https://graph.microsoft.com/beta");
      
      var listItem = new Microsoft.Graph.ListItem
      {
          Fields = new FieldValueSet
          {
              AdditionalData = new Dictionary<string, object>()
              {
                  {"Country", "Palestine"},
                  { "My_x0020_Field", "2000"}//Custom field with spaces
              }
          }
          , ContentType = new ContentTypeInfo() {
              Id = "0x5465424879454894654564654F300A1C2CDC00E306F9F19B9654654654654" //this is a sample content type id acquired in step 6
          }
      };
      
      var request = client.Sites[siteID].Lists[listID].Items[listItemID].Request();
      var result = await request.UpdateAsync(listItem);
      

      希望这对某人有所帮助

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-08-22
        • 1970-01-01
        • 2020-09-02
        • 1970-01-01
        • 2023-02-26
        • 2021-05-20
        • 1970-01-01
        • 2021-03-02
        相关资源
        最近更新 更多