【问题标题】:Get the Sharepoint site for a Group and upload a file using Graph获取组的 Sharepoint 站点并使用 Graph 上传文件
【发布时间】:2021-04-29 13:48:15
【问题描述】:

通过 Teams 应用程序使用 MS Graph SDK,我正在尝试获取组的 Sharepoint 站点并将文件上传到该站点。我无法获得对网站驱动器的引用,它对我来说总是空的。这是我正在尝试的:

var siteName = "testSite";
var site = (await graphService.Groups[groupId].Sites.Request().GetAsync())
    .FirstOrDefault(x => x.DisplayName == SiteName);   

using var wc = new WebClient();
using var stream = new MemoryStream(wc.DownloadData(attachment.DownloadUrl));
// site.Drive is always null
var uploadedFile = await site.Drive.Root
    .ItemWithPath($"Test/123/file.jpg").Content.Request().PutAsync<DriveItem>(stream);  

应用程序拥有Files.ReadWrite.AllGroup.Read.AllSites.ReadWrite.All 权限。

使用 Postman,我在调用 groups/{{id}}/site/root 时得到以下信息,使用相同的令牌(隐藏的值都是正确的)

【问题讨论】:

    标签: c# sharepoint microsoft-teams onedrive microsoft-graph-sdks


    【解决方案1】:

    您可以尝试使用以下方式为群组网站上传文件:

       var item = await graphClient.Groups[groupId].Drive.Root
                   .ItemWithPath("test.docx")
                   .Content
                   .Request()
                   .PutAsync<DriveItem>(stream);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-12
      • 1970-01-01
      • 2018-05-06
      • 2017-06-10
      • 1970-01-01
      • 2021-12-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多