SharePoint.Contents

語法

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

關於

回傳一個階層式表格,包含指定 SharePoint 網站url的資料夾與檔案。 表格顯示目前層級的項目,並不會遞迴回傳網站中的每個檔案。 對於資料夾,欄位 Content 包含一個巢狀表格,可用來導航到資料夾內容。 對於檔案,欄位以 Content 二進位值的形式包含檔案內容。 若要回傳網站及其子資料夾中所有檔案的平面表格,請使用 SharePoint.Files。 每一列同時包含 Name、 Extension、 Date createdAttributesDate accessedDate modified和 Folder Path 欄位。 資料夾列的值是空 Extension 的。 Date accessed 同時 null 用於資料夾和檔案。 這個 Folder Path 值是包含該項目的資料夾的絕對網址。 網站網址不能包含查詢字串或片段。 可以指定 options 以控制下列選項:

  • ApiVersion:數字 (14 或 15) 或文字「Auto」,其指定用於此網站的 SharePoint API 版本。 若未指定,會使用 API 第 14 版。 當指定為 Auto 時,如果可能,會自動偵測伺服器版本,否則版本會預設為 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 會自動使用。 API 版本 14 在實作 2.0 中不被支援。

範例 1

回傳使用原始實作的頂層 SharePoint 內容。 由於未指定選項,故使用 API 版本 14。

Usage

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

Output

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

範例 2

使用原始實作並自動選擇 API 來回傳 Shared Documents 函式庫中的每個 .xlsx 檔案。 擴充的比較不區分大小寫。

Usage

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

Output

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

範例 3

使用 Implementation 2.0 來回傳 Shared Documents 函式庫中 Reports 資料夾的即時內容。 實作 2.0 預設使用 API 版本 15。

Usage

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

Output

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

範例 4

透過瀏覽網站的階層內容,返回 Budget.xlsx 的二進位內容。

Usage

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

Output

The binary content of Budget.xlsx.