Skip to content

Commit ca480c8

Browse files
committed
SharePoint API: example to download files from lib
1 parent a56bc5e commit ca480c8

File tree

21 files changed

+228
-46
lines changed

21 files changed

+228
-46
lines changed

examples/auth/with_adal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
def acquire_token():
13-
import adal # pylint: disable=E0401
13+
import adal # pylint: disable=E0401
1414

1515
settings = load_settings()
1616
authority_url = "https://login.microsoftonline.com/{0}".format(

examples/onedrive/folders/list_with_files.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
3-
"""
1+
""" """
42

53
from office365.graph_client import GraphClient
64
from office365.onedrive.driveitems.driveItem import DriveItem

examples/outlook/messages/create_draft_with_attachments.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
3-
"""
1+
""" """
42

53
import base64
64

examples/sharepoint/files/download_by_shared_link.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
3-
"""
1+
""" """
42

53
import os
64
import tempfile
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
Demonstrates how to download a files from SharePoint library
3+
"""
4+
5+
import tempfile
6+
from pathlib import Path
7+
8+
from office365.sharepoint.client_context import ClientContext
9+
from tests import test_client_credentials, test_team_site_url
10+
11+
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
12+
13+
doc_lib = ctx.web.lists.get_by_title("Documents")
14+
items = (
15+
doc_lib.items.select(["FileSystemObjectType"])
16+
.select(["Id", "FileRef", "FileDirRef", "FileLeafRef"])
17+
.filter("FSObjType eq 0")
18+
.get_all()
19+
.execute_query()
20+
)
21+
22+
download_root_path = Path(tempfile.mkdtemp())
23+
24+
for item in items:
25+
26+
download_path = download_root_path / item.properties.get("FileDirRef").lstrip("/")
27+
download_path.mkdir(parents=True, exist_ok=True)
28+
29+
download_file_path = download_path / item.properties.get("FileLeafRef")
30+
31+
with open(download_file_path, "wb") as f:
32+
item.file.download(f).execute_query()
33+
print(f"File has been downloaded into {f.name}")

examples/sharepoint/folders/folder_exists.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
How to determine whether folder exist?
2+
How to determine whether folder exist?
33
"""
44

55
from office365.sharepoint.client_context import ClientContext

examples/sharepoint/folders/folder_exists_v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
How to determine whether folder exist?
2+
How to determine whether folder exist?
33
"""
44

55
from office365.runtime.client_request_exception import ClientRequestException

examples/sharepoint/listitems/update.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
3-
"""
1+
""" """
42

53
import sys
64
from random import randint

examples/sharepoint/lists/import_lib.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
3-
"""
1+
""" """
42

53
from random import randrange
64

examples/sharepoint/run_test_rate_limit.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
"""
1+
""" """
32

43
import asyncio
54

0 commit comments

Comments
 (0)