---
title: SharePoint.Contents – ดึงเนื้อหาจาก SharePoint Site เป็น Navigation Table
url: https://www.thepexcel.com/functions/power-query/accessing-data-functions/sharepoint-contents/
type: function-explainer
program: Power Query
syntax: "SharePoint.Contents(url as text, optional options as nullable record) as table"
date: 2025-12-12
updated: 2025-12-23
scores:
  popularity: 7
  difficulty: 4
  usefulness: 7
---

# SharePoint.Contents – ดึงเนื้อหาจาก SharePoint Site เป็น Navigation Table

> SharePoint.Contents ดึงรายการโฟลเดอร์และไฟล์ทั้งหมดจาก SharePoint site เป็น navigation table ที่สามา

## คำอธิบาย

SharePoint.Contents ดึงรายการโฟลเดอร์และไฟล์ทั้งหมดจาก SharePoint site เป็น navigation table ที่สามารถ drill down ไปยัง Document Libraries และ Lists ต่างๆ ได้

## Syntax

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

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| url | Yes | text |  | URL ของ SharePoint site เช่น https://company.sharepoint.com/sites/TeamSite (ต้องเป็น site URL ไม่ใช่ folder URL) |
| options | No | nullable record | null | Record สำหรับกำหนด options เช่น ApiVersion (14, 15 หรือ "Auto") และ Implementation (2.0 หรือ null) |

## ตัวอย่าง

### 1. ดึงเนื้อหาทั้งหมดจาก SharePoint Site

```excel
let
    Source = SharePoint.Contents("https://company.sharepoint.com/sites/TeamSite")
in
    Source
```

**ผลลัพธ์:** `Navigation table ที่มี Document Libraries และ Lists ต่างๆ ของ site`

ผลลัพธ์เป็นตารางแสดง root level ของ site ซึ่งจะมีรายการ Document Libraries และ Lists พร้อม Content column ให้คลิก expand เพื่อดูเนื้อหาภายใน

### 2. ใช้ ApiVersion 15 สำหรับ SharePoint ภาษาไทย

```excel
let
    Source = SharePoint.Contents(
        "https://company.sharepoint.com/sites/ThaiTeam",
        [ApiVersion = 15]
    )
in
    Source
```

**ผลลัพธ์:** `Navigation table ดึงมาโดยใช้ API version 15 ซึ่งรองรับภาษาไม่ใช่อังกฤษ`

SharePoint site ที่ใช้ภาษาอื่นนอกจากอังกฤษ เช่น ไทย จีน หรือญี่ปุ่น จำเป็นต้องใช้ ApiVersion 15 ขึ้นไป เพราะ version 14 อาจมีปัญหา encoding

### 3. ใช้ Auto Detect สำหรับ ApiVersion

```excel
let
    Source = SharePoint.Contents(
        "https://company.sharepoint.com/sites/Sales",
        [ApiVersion = "Auto"]
    )
in
    Source
```

**ผลลัพธ์:** `Navigation table โดยระบบจะตรวจสอบ version ของ SharePoint เอง`

เมื่อใช้ "Auto" Power Query จะ detect version ของ SharePoint อัตโนมัติ ถ้าตรวจไม่สำเร็จก็จะ fallback ไป version 14

### 4. ใช้ Implementation 2.0 Connector

```excel
let
    Source = SharePoint.Contents(
        "https://company.sharepoint.com/sites/HR",
        [ApiVersion = 15, Implementation = 2.0]
    )
in
    Source
```

**ผลลัพธ์:** `Navigation table โดยใช้ connector version 2.0 ที่มี API ปรับปรุง`

Implementation 2.0 มี API ใหม่และ usability ดีขึ้น แต่มีข้อจำกัดเรื่อง join limit สูงสุด 12 operations ต้องระวังถ้า query ซับซ้อน

## หมายเหตุเพิ่มเติม

- ใช้ [ApiVersion = 15] เสมอสำหรับ SharePoint ภาษาไทยหรือภาษาอื่นที่ไม่ใช่อังกฤษ เพื่อให้รองรับ encoding ของภาษาต่างๆ

- ฟังก์ชัน SharePoint.Contents เหมาะสำหรับสำรวจโครงสร้างไซต์ทั้งหมด ถ้าต้องการดึงไฟล์โดยตรงควรใช้ SharePoint.Files แทน

- การใช้ Implementation เวอร์ชัน 2.0 มีข้อจำกัดเรื่องจำนวน join operations สูงสุด 12 operations ต้องระวังถ้ามีการประมวลผลที่ซับซ้อน

- ผลลัพธ์ที่ได้จะเป็นตารางแบบลำดับชั้น ต้องคลิกคอลัมน์เนื้อหาหรือใช้ Table.ExpandTableColumn เพื่อขยายดูข้อมูลภายใน

- ก่อนใช้งานควรตรวจสอบสิทธิ์การเข้าถึงไซต์ SharePoint ให้ครบถ้วน เพื่อหลีกเลี่ยงข้อผิดพลาดระหว่างการดึงข้อมูล

## คำถามที่พบบ่อย

**Q: SharePoint.Contents ต่างจาก SharePoint.Files อย่างไร?**

SharePoint.Contents ดึง navigation table ของทั้ง site ต้อง drill down ไปหา Document Library แต่ละชั้น ส่วน SharePoint.Files ดึงเฉพาะไฟล์จาก Document Library ที่ระบุโดยตรง ถ้าต้องการดึงไฟล์โดยตรงใช้ SharePoint.Files จะตรงประเด็นกว่า

**Q: ต้องใช้ ApiVersion 15 เสมอหรือ?**

ถ้า SharePoint site ใช้ภาษาอังกฤษ version 14 ก็พอ แต่ถ้าใช้ภาษาอื่นต้องใช้ 15 ขึ้นไป ผมแนะนำใส่ [ApiVersion = 15] เสมอเพื่อความปลอดภัย

**Q: เกิด error 401 Unauthorized ต้องทำอย่างไร?**

Error นี้เกิดจากไม่มีสิทธิ์เข้าถึง SharePoint site ให้ไปที่ Data Source Settings แล้ว Clear Permissions แล้ว sign in ใหม่ หรือติดต่อ admin เพื่อขอสิทธิ์

## แหล่งข้อมูลเพิ่มเติม

- [เอกสาร Microsoft: SharePoint.Contents](https://learn.microsoft.com/en-us/powerquery-m/sharepoint-contents) _(official)_
- [เอกสาร Microsoft: ตัวเชื่อมต่อ SharePoint Online](https://learn.microsoft.com/en-us/power-query/connectors/sharepoint-online-list) _(official)_

---

_Source: [https://www.thepexcel.com/functions/power-query/accessing-data-functions/sharepoint-contents/](https://www.thepexcel.com/functions/power-query/accessing-data-functions/sharepoint-contents/)_
