Upload, download, copy, move, delete, share, and manage files in SharePoint document libraries.
| Requirement | Description | Reference |
|---|---|---|
| Site Owner or Member role on the library | Required to upload, update, and delete files. Read access for download. | SharePoint permissions |
graph TD
subgraph Site
Library["Document Library e.g. Shared Documents"]
end
subgraph Library
Folder["Folder"]
File["File"]
Folder --> File
end
subgraph "List Item"
Item["List Item"]
Attach["Attachment"]
Item --> Attach
end
Library --> Folder
Library --> File
Files live inside document libraries. They can be organized in folders.
Separately, list items can have attachments — see
listitems/attachments/ for attachment
operations.
from office365.sharepoint.client_context import ClientContext
ctx = ClientContext("https://contoso.sharepoint.com/sites/team").with_client_secret(
"contoso.onmicrosoft.com", "client_id", "client_secret"
)
# Upload a small file
with open("./report.docx", "rb") as f:
uploaded = ctx.web.default_document_library().root_folder.upload_file("report.docx", f.read()).execute_query()
print(f"Uploaded: {uploaded.serverRelativeUrl}")
# Download it back
downloaded = uploaded.get_content().execute_query()
print(f"Downloaded: {len(downloaded.content)} bytes")| What | File | Notes |
|---|---|---|
| Upload small file | upload.py |
Upload file < 4 MB |
| Upload large file | upload_large.py |
Chunked upload session for large files |
| Upload with checksum | upload_with_checksum.py |
Upload with MD5 verification |
| Upload CSV | upload_csv.py |
Upload a CSV data file |
| Upload JSON | upload_json.py |
Upload a JSON data file |
| Replace content | replace.py |
Replace file content via binary stream |
| What | File | Notes |
|---|---|---|
| Download file | download.py |
Simple file download |
| Download large file | download_large.py |
Streaming download with progress |
| Download from URL | download_from_url.py |
Download using absolute URL |
| Download all from library | download_from_lib.py |
Batch download all files in a library |
| Download by sharing link | download_by_shared_link.py |
Download via guest/anonymous link |
| Download recent | download_recent.py |
Download most recently uploaded file |
| Download versions | download_versions.py |
Download specific file versions |
| Get content | get_content.py |
Download as bytes in memory |
| What | File | Notes |
|---|---|---|
| Copy file | copy_file.py |
Copy to another folder |
| Copy with new name | copy_file_with_name.py |
Copy and rename |
| Copy by path | copy_using_path.py |
Copy using server-relative paths |
| Move file | move_file.py |
Move to another folder |
| What | File | Notes |
|---|---|---|
| Delete / recycle | delete.py |
Permanent delete or recycle |
| What | File | Notes |
|---|---|---|
| Get properties | get_props.py |
Name, size, URL, timestamps |
| Get extended properties | get_extended_props.py |
List item all fields |
| Get system metadata | get_system_metadata.py |
Author, modified by, created |
| Check existence | exists.py |
Check if a file exists |
| List all items | get_all_items.py |
Enumerate files and folders in a library |
| Get recent files | get_recent_files.py |
Recently modified files |
| Get download link | get_download_link.py |
Pre-authorized download URL |
| What | File | Notes |
|---|---|---|
| Check out / check in | checkout_checkin.py |
Lock, edit, and release a file |
| Get checked-out files | get_checked_out.py |
List all checked-out files in a library |
| Get checkout type | get_checkout_type.py |
Check if a file is checked out and by whom |
| Publish / unpublish | publish_unpublish.py |
Submit for content approval |
| Approve / deny | approve_deny.py |
Approve or reject a submitted file |
Sharing operations for files are in the
sharing/directory.
| What | File | Notes |
|---|---|---|
| Get by sharing link | get_by_sharing_link.py |
Resolve file from a sharing link |
| Download by sharing link | download_by_shared_link.py |
Download via guest/anonymous link |
| What | File | Notes |
|---|---|---|
| Create Excel | create_excel.py |
Create an Excel workbook |
| Create Word | create_word.py |
Create a Word document |
| Create wiki page | create_wiki.py |
Create a wiki page |
| Rename | rename_page.py |
Rename a file |
| What | File | Notes |
|---|---|---|
| Get permissions | permissions/get.py |
Effective permissions for a file |
| List permissions | permissions/list.py |
User effective permissions |
| Check permission | permissions/check.py |
Does user have specific access? |
| Assign permission | permissions/assign.py |
Grant permissions via role assignment |
| What | File | Notes |
|---|---|---|
| List versions | versions/list.py |
All versions of a file |
| Get by label | versions/get_by_label.py |
Get a specific version |
| Restore version | versions/restore_version.py |
Restore a previous version |
| What | File | Notes |
|---|---|---|
| Find label downgrades | find_label_downgrades.py |
Detect sensitivity label downgrades via audit logs |
| Find unused files | find_unused_files.py |
Files with no user access in N days |
| Version storage report | version_storage_report.py |
Analyze version count and storage cost per file |
| What | File | Notes |
|---|---|---|
| Upload attachment | ../listitems/attachments/upload.py |
Attach a file to a list item |
| Download attachment | ../listitems/attachments/download.py |
Download from a list item |
| List attachments | ../listitems/attachments/list.py |
Enumerate attachments on an item |
| Delete attachment | ../listitems/attachments/delete.py |
Remove an attachment |
Note: Attachments are files attached to list items, not documents in a library. See
listitems/attachments/for all attachment operations.