-
-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
170 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
123 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
""" | ||
Demonstrates how to download a file from SharePoint site | ||
Note: this method is considered a deprecated approach nowadays! | ||
Refer download.py which demonstrates how to download a file | ||
""" | ||
import os | ||
import tempfile | ||
|
||
from office365.sharepoint.client_context import ClientContext | ||
from office365.sharepoint.files.file import File | ||
from tests import test_client_credentials, test_team_site_url | ||
|
||
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials) | ||
file_url = "Shared Documents/Sample.pdf" | ||
# file_url = "Shared Documents/report '123.csv" | ||
download_path = os.path.join(tempfile.mkdtemp(), os.path.basename(file_url)) | ||
with open(download_path, "wb") as local_file: | ||
file = ctx.web.get_file_by_server_relative_url(file_url).get().execute_query() | ||
resp = File.open_binary(ctx, file.properties["ServerRelativeUrl"]) | ||
resp.raise_for_status() | ||
local_file.write(resp.content) | ||
print("[Ok] file has been downloaded into: {0}".format(download_path)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
""" | ||
Demonstrates how to upload a CSV file to a SharePoint site | ||
""" | ||
import os | ||
|
||
from office365.sharepoint.client_context import ClientContext | ||
from tests import test_team_site_url, test_user_credentials | ||
|
||
ctx = ClientContext(test_team_site_url).with_credentials(test_user_credentials) | ||
|
||
list_title = "Documents" | ||
folder = ctx.web.lists.get_by_title(list_title).root_folder | ||
path = "../../data/Financial Sample.csv" | ||
with open(path, "r") as content_file: | ||
file_content = content_file.read().encode("utf-8-sig") | ||
file = folder.upload_file(os.path.basename(path), file_content).execute_query() | ||
print("File has been uploaded into: {0}".format(file.serverRelativeUrl)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
""" | ||
Demonstrates how to apply filtering to list collection | ||
In the provided example only the user defined lists are getting returned | ||
""" | ||
|
||
from office365.sharepoint.client_context import ClientContext | ||
from tests import test_client_credentials, test_site_url, test_team_site_url | ||
|
||
ctx = ClientContext(test_site_url).with_credentials(test_client_credentials) | ||
result = ( | ||
ctx.web.lists.get_by_title("Documents") | ||
.items.get() | ||
.filter("FileLeafRef eq 'report.csv'") | ||
.execute_query() | ||
) | ||
for item in result: | ||
print(item.properties) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
""" | ||
Demonstrates how to retrieve deleted items (of File type) | ||
""" | ||
from office365.sharepoint.changes.query import ChangeQuery | ||
from office365.sharepoint.client_context import ClientContext | ||
from tests import test_client_credentials, test_team_site_url | ||
|
||
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials) | ||
# result = ctx.web.default_document_library().get_changes(ChangeQuery(list_=False, item=True)).execute_query() | ||
result = ( | ||
ctx.web.recycle_bin.get().execute_query() | ||
) # filter("ItemType eq 1").execute_query() | ||
for item in result: | ||
print(item.properties) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from office365.sharepoint.client_context import ClientContext | ||
from office365.sharepoint.listitems.collection import ListItemCollection | ||
from tests import test_client_credentials, test_team_site_url | ||
|
||
|
||
def print_progress(items): | ||
# type: (ListItemCollection) -> None | ||
print("Items read: {0}".format(len(items))) | ||
|
||
|
||
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials) | ||
large_list = ctx.web.lists.get_by_title("Contacts_Large") | ||
all_items = large_list.items.get_all(5000, print_progress).execute_query() | ||
print("Total items count: {0}".format(len(all_items))) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters