SharePoint.Contents

语法

SharePoint.Contents(url as text, optional options as nullable record) as table

关于

返回一个分层表,其中包含在指定的SharePoint站点url中找到的文件夹和文件。 该表显示当前级别的项,并且不会以递归方式返回站点中的每个文件。 对于文件夹,该 Content 列包含一个嵌套表,可用于导航到文件夹内容。 对于文件,该 Content 列包含文件内容作为二进制值。 若要返回站点及其子文件夹中所有文件的平面表,请使用 SharePoint.Files。 每行还包含 Name、Extension、Date accessed、Date modifiedDate created、 Attributes和Folder Path列。 文件夹行具有空 Extension 值。 Date accessed 适用于 null 文件夹和文件。 该值 Folder Path 是包含该项的文件夹的绝对 URL。 网站 URL 不能包含查询字符串或片段。 可以指定 options 来控制以下选项:

  • ApiVersion:数字(14 或 15)或文本“自动”,指定要用于此网站的 SharePoint API 版本。 如果未指定,则使用 API 版本 14。 指定“自动”时,如果可能,将自动发现服务器版本,否则版本默认为 14。 非英语 SharePoint 网站至少需要版本 15。
  • Implementation:可选。 指定要使用的 SharePoint 连接器版本。 接受的值为“2.0”或 null。 如果值为“2.0”,则使用 SharePoint 连接器的 2.0 实现。 如果值为 null,则使用 SharePoint 连接器的原始实现。

对于 SharePoint.Contents,原始实现支持 ApiVersion 值 14、15 和 "Auto"。 ApiVersion如果未指定,则使用版本 14。 使用实现 2.0 时, ApiVersion 不需要指定,因为会自动使用 API 版本 15。 实现 2.0 不支持 API 版本 14。

示例 1

使用原始实现返回顶级SharePoint内容。 由于未指定任何选项,因此使用 API 版本 14。

用法

SharePoint.Contents("https://contoso.sharepoint.com/sites/Contoso")

输出

A hierarchical table containing the top-level folders and files in the site.

示例 2

使用具有自动 API 选择的原始实现可返回共享文档库中的每一 .xlsx 个文件。 扩展比较不区分大小写。

用法

let
    Source = SharePoint.Contents(
        "https://contoso.sharepoint.com/sites/Contoso",
        [ApiVersion = "Auto"]
    ),
    SharedDocuments = Source{[Name = "Shared Documents"]}[Content],
    ExcelWorkbooks = Table.SelectRows(
        SharedDocuments,
        each Comparer.OrdinalIgnoreCase([Extension], ".xlsx") = 0
    )
in
    ExcelWorkbooks

输出

A table containing only the files in the Shared Documents library whose Extension value is .xlsx.

示例 3

使用实现 2.0 返回共享文档库中“报表”文件夹的即时内容。 实现 2.0 默认使用 API 版本 15。

用法

let
    Source = SharePoint.Contents(
        "https://contoso.sharepoint.com/sites/Contoso",
        [Implementation = "2.0"]
    ),
    SharedDocuments = Source{[Name = "Shared Documents"]}[Content],
    Reports = SharedDocuments{[Name = "Reports"]}[Content]
in
    Reports

输出

A hierarchical table containing the immediate folders and files in the Reports folder.

示例 4

通过导航网站的分层内容返回 Budget.xlsx 的二进制内容。

用法

let
    Source = SharePoint.Contents(
        "https://contoso.sharepoint.com/sites/Contoso",
        [Implementation = "2.0"]
    ),
    SharedDocuments = Source{[Name = "Shared Documents"]}[Content],
    Reports = SharedDocuments{[Name = "Reports"]}[Content],
    Budget = Reports{[Name = "Budget.xlsx"]}[Content]
in
    Budget

输出

The binary content of Budget.xlsx.