【问题标题】:Microsoft Graph API SDK for SharePoint to query a fileMicrosoft Graph API SDK for SharePoint 用于查询文件
【发布时间】:2021-12-06 23:43:21
【问题描述】:

我尝试使用 Graph API SDK 来查询 SharePoint 网站中的文件

        var site = await graphClient.Sites["myDomain"]
            .SiteWithPath("relativePath").Request()
            .GetAsync().ConfigureAwait(false);

        var drive = await graphClient.Sites["myDomain]
            .SiteWithPath("relativePath").Lists["mylib"].Drive
            .Request().GetAsync().ConfigureAwait(false);

        var file = await graphClient.Sites[site.Id]
            .Drives[drive.Id].Root.ItemWithPath("/folder1").Children["myfile.txt"]
            .Request().GetAsync().ConfigureAwait(false);

这是有效的,我得到了文件。

我尝试将三个步骤合二为一,

        var file = await graphClient.Sites["myDomain"]
            .SiteWithPath("relativePath").Lists["mylib"].Drive
            .Root.ItemWithPath("/folder1").Children["myfile.txt"]
            .Request().GetAsync().ConfigureAwait(false);

但它给出了错误的请求错误。怎么了?最好的方法是什么?

【问题讨论】:

  • 您收到什么错误信息?我想 Url specified is invalid 因为 Graph 不理解 /sites/your-domain:/sites/site-name:/lists/your-lib/drive 之外的任何路径

标签: microsoft-graph-api sharepoint-online microsoft-graph-sdks


【解决方案1】:

Graph 不接受您使用的导航。 根据 get files 文档,您需要站点 ID。

# Valid
GET /sites/mydomain.sharepoint.com:/relativePath/lists/mylib/drive

# Invalid addition to above url
GET /sites/mydomain.sharepoint.com:/relativePath/lists/mylib/drive/root:/myfile.txt:

如果您没有站点ID,您可以在获取列表驱动调用中展开列表关系,并使用站点ID 来请求文件。这将是两个请求。

var drive = await graphServiceClient
    .Sites["mydomain.sharepoint.com"]
    .SiteWithPath(relativePath)
    .Lists["mylib"]
    .Drive
    .Request()
    .Expand("list")
    .GetAsync()
    .ConfigureAwait(false);

var file = await graphServiceClient
    .Sites[drive.List.ParentReference.SiteId]
    .Drives[drive.Id]
    .Root.ItemWithPath("/Folder 1")
    .Children["myfile.txt"]
    .Request().GetAsync().ConfigureAwait(false);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-04
    • 1970-01-01
    • 2021-10-14
    • 2016-02-25
    • 1970-01-01
    • 2020-08-15
    • 1970-01-01
    相关资源
    最近更新 更多