Skip to content

Commit ca480c8

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

21 files changed

+228
-46
lines changed

examples/auth/with_adal.py

+1-1
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

+1-3
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

+1-3
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

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
3-
"""
1+
""" """
42

53
import os
64
import tempfile
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

+1-1
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

+1-1
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

+1-3
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

+1-3
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

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
"""
1+
""" """
32

43
import asyncio
54

examples/sharepoint/tenant/get_site.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
3-
"""
1+
""" """
42

53
from office365.sharepoint.client_context import ClientContext
64
from tests import test_admin_credentials, test_admin_site_url, test_team_site_url

examples/sharepoint/userprofile/get_properties.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Gets user properties for the specified user
2+
Gets user properties for the specified user
33
"""
44

55
from pprint import pprint

examples/sharepoint/views/export_view.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
3-
"""
1+
""" """
42

53
import json
64

examples/sharepoint/webs/clear_web.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
3-
"""
1+
""" """
42

53
from typing import List
64

examples/sharepoint/webs/get_all.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
3-
"""
1+
""" """
42

53
from office365.sharepoint.client_context import ClientContext
64
from tests import test_client_credentials, test_site_url

generator/import_metadata.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ def export_to_file(path, content):
2626
"--endpoint",
2727
dest="endpoint",
2828
help="Import metadata endpoint",
29-
default="graph",
29+
default="sharepoint",
3030
)
3131
parser.add_argument(
3232
"-p",
3333
"--path",
3434
dest="path",
35-
default="./metadata/Graph.xml",
35+
default="./metadata/SharePoint.xml",
3636
help="Import metadata endpoint",
3737
)
3838

generator/metadata/Graph.xml

+85
Original file line numberDiff line numberDiff line change
@@ -6320,6 +6320,54 @@
63206320
<Annotations Target="microsoft.graph.certification/isCertifiedByMicrosoft">
63216321
<Annotation Term="Org.OData.Core.V1.Computed" Bool="true"/>
63226322
</Annotations>
6323+
<Annotations Target="microsoft.graph.certificateAuthorityDetail">
6324+
<Annotation Term="Org.OData.Capabilities.V1.CountRestrictions">
6325+
<Record>
6326+
<PropertyValue Property="Countable" Bool="true"/>
6327+
</Record>
6328+
</Annotation>
6329+
<Annotation Term="Org.OData.Capabilities.V1.ExpandRestrictions">
6330+
<Record>
6331+
<PropertyValue Property="Expandable" Bool="false"/>
6332+
</Record>
6333+
</Annotation>
6334+
<Annotation Term="Org.OData.Capabilities.V1.FilterRestrictions">
6335+
<Record>
6336+
<PropertyValue Property="Filterable" Bool="true"/>
6337+
</Record>
6338+
</Annotation>
6339+
<Annotation Term="Org.OData.Capabilities.V1.NavigationRestrictions">
6340+
<Record>
6341+
<PropertyValue Property="Referenceable" Bool="false"/>
6342+
</Record>
6343+
</Annotation>
6344+
<Annotation Term="Org.OData.Capabilities.V1.SkipSupported" Bool="false"/>
6345+
<Annotation Term="Org.OData.Capabilities.V1.TopSupported" Bool="true"/>
6346+
</Annotations>
6347+
<Annotations Target="microsoft.graph.certificateBasedAuthPki">
6348+
<Annotation Term="Org.OData.Capabilities.V1.CountRestrictions">
6349+
<Record>
6350+
<PropertyValue Property="Countable" Bool="true"/>
6351+
</Record>
6352+
</Annotation>
6353+
<Annotation Term="Org.OData.Capabilities.V1.ExpandRestrictions">
6354+
<Record>
6355+
<PropertyValue Property="Expandable" Bool="false"/>
6356+
</Record>
6357+
</Annotation>
6358+
<Annotation Term="Org.OData.Capabilities.V1.FilterRestrictions">
6359+
<Record>
6360+
<PropertyValue Property="Filterable" Bool="true"/>
6361+
</Record>
6362+
</Annotation>
6363+
<Annotation Term="Org.OData.Capabilities.V1.NavigationRestrictions">
6364+
<Record>
6365+
<PropertyValue Property="Referenceable" Bool="false"/>
6366+
</Record>
6367+
</Annotation>
6368+
<Annotation Term="Org.OData.Capabilities.V1.SkipSupported" Bool="false"/>
6369+
<Annotation Term="Org.OData.Capabilities.V1.TopSupported" Bool="true"/>
6370+
</Annotations>
63236371
<Annotations Target="microsoft.graph.crossTenantAccessPolicyConfigurationDefault">
63246372
<Annotation Term="Org.OData.Capabilities.V1.CountRestrictions">
63256373
<Record>
@@ -17800,6 +17848,11 @@ within the time frame of their original request."/>
1780017848
<Member Name="defaultConfiguredIdp" Value="6"/>
1780117849
<Member Name="unknownFutureValue" Value="7"/>
1780217850
</EnumType>
17851+
<EnumType Name="certificateAuthorityType">
17852+
<Member Name="root" Value="0"/>
17853+
<Member Name="intermediate" Value="1"/>
17854+
<Member Name="unknownFutureValue" Value="2"/>
17855+
</EnumType>
1780317856
<EnumType Name="crossTenantAccessPolicyTargetConfigurationAccessType">
1780417857
<Member Name="allowed" Value="1"/>
1780517858
<Member Name="blocked" Value="2"/>
@@ -26256,6 +26309,7 @@ within the time frame of their original request."/>
2625626309
<NavigationProperty Name="deletedItems" Type="Collection(graph.directoryObject)" ContainsTarget="true"/>
2625726310
<NavigationProperty Name="federationConfigurations" Type="Collection(graph.identityProviderBase)" ContainsTarget="true"/>
2625826311
<NavigationProperty Name="onPremisesSynchronization" Type="Collection(graph.onPremisesDirectorySynchronization)" ContainsTarget="true"/>
26312+
<NavigationProperty Name="publicKeyInfrastructure" Type="graph.publicKeyInfrastructureRoot" ContainsTarget="true"/>
2625926313
<NavigationProperty Name="subscriptions" Type="Collection(graph.companySubscription)" ContainsTarget="true"/>
2626026314
</EntityType>
2626126315
<EntityType Name="administrativeUnit" BaseType="graph.directoryObject" OpenType="true">
@@ -26289,6 +26343,9 @@ within the time frame of their original request."/>
2628926343
<Property Name="configuration" Type="graph.onPremisesDirectorySynchronizationConfiguration"/>
2629026344
<Property Name="features" Type="graph.onPremisesDirectorySynchronizationFeature" Nullable="false"/>
2629126345
</EntityType>
26346+
<EntityType Name="publicKeyInfrastructureRoot" BaseType="graph.entity">
26347+
<NavigationProperty Name="certificateBasedAuthConfigurations" Type="Collection(graph.certificateBasedAuthPki)" ContainsTarget="true"/>
26348+
</EntityType>
2629226349
<EntityType Name="companySubscription" BaseType="graph.entity">
2629326350
<Property Name="commerceSubscriptionId" Type="Edm.String"/>
2629426351
<Property Name="createdDateTime" Type="Edm.DateTimeOffset"/>
@@ -26582,9 +26639,29 @@ within the time frame of their original request."/>
2658226639
<Property Name="displayName" Type="Edm.String"/>
2658326640
<Property Name="type" Type="Edm.String"/>
2658426641
</EntityType>
26642+
<EntityType Name="certificateAuthorityDetail" BaseType="graph.directoryObject">
26643+
<Property Name="certificate" Type="Edm.Binary" Nullable="false"/>
26644+
<Property Name="certificateAuthorityType" Type="graph.certificateAuthorityType"/>
26645+
<Property Name="certificateRevocationListUrl" Type="Edm.String"/>
26646+
<Property Name="createdDateTime" Type="Edm.DateTimeOffset"/>
26647+
<Property Name="deltaCertificateRevocationListUrl" Type="Edm.String"/>
26648+
<Property Name="displayName" Type="Edm.String"/>
26649+
<Property Name="expirationDateTime" Type="Edm.DateTimeOffset" Nullable="false"/>
26650+
<Property Name="isIssuerHintEnabled" Type="Edm.Boolean"/>
26651+
<Property Name="issuer" Type="Edm.String"/>
26652+
<Property Name="issuerSubjectKeyIdentifier" Type="Edm.String"/>
26653+
<Property Name="thumbprint" Type="Edm.String" Nullable="false"/>
26654+
</EntityType>
2658526655
<EntityType Name="certificateBasedAuthConfiguration" BaseType="graph.entity">
2658626656
<Property Name="certificateAuthorities" Type="Collection(graph.certificateAuthority)" Nullable="false"/>
2658726657
</EntityType>
26658+
<EntityType Name="certificateBasedAuthPki" BaseType="graph.directoryObject">
26659+
<Property Name="displayName" Type="Edm.String"/>
26660+
<Property Name="lastModifiedDateTime" Type="Edm.DateTimeOffset" Nullable="false"/>
26661+
<Property Name="status" Type="Edm.String"/>
26662+
<Property Name="statusDetails" Type="Edm.String"/>
26663+
<NavigationProperty Name="certificateAuthorities" Type="Collection(graph.certificateAuthorityDetail)" ContainsTarget="true"/>
26664+
</EntityType>
2658826665
<EntityType Name="contract" BaseType="graph.directoryObject" OpenType="true">
2658926666
<Property Name="contractType" Type="Edm.String"/>
2659026667
<Property Name="customerId" Type="Edm.Guid"/>
@@ -36484,6 +36561,11 @@ within the time frame of their original request."/>
3648436561
<Action Name="resetToSystemDefault" IsBound="true">
3648536562
<Parameter Name="bindingParameter" Type="graph.crossTenantAccessPolicyConfigurationDefault" Nullable="false"/>
3648636563
</Action>
36564+
<Action Name="upload" IsBound="true">
36565+
<Parameter Name="bindingParameter" Type="graph.certificateBasedAuthPki" Nullable="false"/>
36566+
<Parameter Name="uploadUrl" Type="Edm.String" Nullable="false" Unicode="false"/>
36567+
<Parameter Name="sha256FileHash" Type="Edm.String" Nullable="false" Unicode="false"/>
36568+
</Action>
3648736569
<Action Name="activate" IsBound="true">
3648836570
<Parameter Name="bindingParameter" Type="graph.educationAssignment"/>
3648936571
<ReturnType Type="graph.educationAssignment"/>
@@ -39323,6 +39405,9 @@ within the time frame of their original request."/>
3932339405
<Action Name="refresh" IsBound="true">
3932439406
<Parameter Name="bindparameter" Type="graph.workbookPivotTable"/>
3932539407
</Action>
39408+
<Action Name="refresh" IsBound="true">
39409+
<Parameter Name="bindingParameter" Type="graph.accessPackageResource"/>
39410+
</Action>
3932639411
<Action Name="refreshAll" IsBound="true">
3932739412
<Parameter Name="bindparameter" Type="Collection(graph.workbookPivotTable)"/>
3932839413
</Action>

0 commit comments

Comments
 (0)