-
-
Notifications
You must be signed in to change notification settings - Fork 371
Expand file tree
/
Copy pathreplace.py
More file actions
23 lines (16 loc) · 699 Bytes
/
replace.py
File metadata and controls
23 lines (16 loc) · 699 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""
Demonstrates how to replace file content
"""
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)
path = "../../data/report.csv"
print("Uploading a new file...")
with open(path, "rb") as f:
target_file = ctx.web.default_document_library().root_folder.files.upload(f).execute_query()
print("Replacing file content...")
with open(path, "rb") as content_file:
file_content = content_file.read()
target_file.save_binary_stream(file_content).execute_query()
print("Cleaning up resources...")
target_file.delete_object().execute_query()