SharePoint - Download file(s)

Declaration

<AMSHAREPOINT ACTIVITY="download_files"  SESSION="text" SITE="text" VERSION="text (options)" SPOAUTHTYPE="text (options)" AUTHTYPE="text (options)" USERNAME="text" PASSWORD="text" DOMAIN="text" CLIENTID="text" CLIENTSECRET="text" AADTENANTID="text (encrypted)" AADCLIENTID="text (encrypted)" AADCERTIFICATE="text" AADCERTIFICATEPASSWORD="text (encrypted)" AZUREENVIRONMENT="text (options)" CERTIFICATE="text" IGNOREINVALIDCERTIFICATE="YES/NO" TIMEOUT="500" PROXYTYPE="text (options)" PROXYSERVER="text" PROXYUSERNAME="text" PROXYPASSWORD="text (options)" DOWNLOADTYPE="text (options)" URL="text" DESTINATION="text" OVERWRITE="YES/NO" SOURCE="text" DEST="text" RESULTDATASET="text" SUBFOLDERS="YES/NO" KEEPFOLDERSTRUCT="YES/NO" OVERWRITE="YES/NO" EXCLUDE="text" RE="YES/NO" ISNEWERTHAN="%DateSerial+TimeSerial%" ISOLDERTHAN="%DateSerial+TimeSerial%" />

Related Topics

Description

Downloads one or more files from the SharePoint site to a local directory. To specify more than one file, use wildcard characters (for example, * or ?). To specify multiple files or wildcard masks, separate them with a pipe character (for example, source/*.txt|source/*.bak).

NOTE: SharePoint-related error messages appearing in Automate Desktop are sent from your SharePoint site or server. Automate Desktop displays these messages verbatim. For information on SharePoint error messages, refer to Microsoft's SharePoint documentation.

Practical usage

Ideal for automated retrieval of files from a SharePoint site.

Parameters

Connection

Property Type Required Default Markup Description
Connection --- --- --- --- Indicates where this activity's SharePoint credentials should originate from. The available options are:
  • Host (default) - Specifies that a custom set of credentials will be entered for this activity. This option is normally selected if only a single SharePoint activity is required to complete the task.

  • Session - Specifies that credentials should derive from a session created in a previous SharePoint - Create session step. This allows several activities to be linked to a specific session, eliminating redundancy. Multiple sessions can exist within a single task, allowing several SharePoint operations to be automated simultaneously.

NOTE: This parameter does not contain markup and is only displayed in visual mode for task construction and configuration purposes.

Connection - Session

Property Type Required Default Markup Description
Session Text Yes, if Connection is set to Session SharePointSession1 SESSION="mySession1" The name of the session to associate with this activity. This parameter is only active if the Connection parameter is set to Session . If Connection is set to Host, this parameter is ignored and the remainder of the parameters specified below become active.
NOTE: Use the SharePoint - End session activity to end an active SharePoint session.

Connection - Host > Server

Property Type Required Default Markup Description
Version Text (options) Yes, if Connection is set to Host SharePoint 2013 and newer

VERSION="sharepointonline"

The SharePoint version to associate with this activity. The available options are:
  • SharePoint Online - A cloud-based service, hosted by Microsoft as an alternative to installing and deploying SharePoint Server on premises.
  • SharePoint 2013 and newer (default) - SharePoint version 2013 or newer - includes SharePoint Foundation 2013/2016/2019 and SharePoint Server 2013/2016/2019.
Site Text Yes, if Connection is set to Host (Empty) SITE="http://myServer/tech" The SharePoint site to access. A SharePoint site is a collection of pages, site templates, lists, and libraries configured for the purpose of achieving an express goal.
Refer to these parameters when Version is set to SharePoint Online.
Authentication type Type (options) Yes Default
  • SPOAUTHTYPE="default"
  • SPOAUTHTYPE="spapponly"
  • SPOAUTHTYPE="aadapponly"
  • SPOAUTHTYPE="aaddelegated"
  • SPOAUTHTYPE="interactive"
Specifies the authentication type to use with the connection. The available options are:
  • Default (default) - Authenticates using a valid SharePoint username and password.

    NOTE: This type does not support multi-factor authentication/single sign-on.
  • SharePoint App Only - Authenticates using a valid SharePoint Client ID value, Client Secret value, and Azure environment selection.

  • Azure AD App Only - Authenticates using a valid Azure AD Directory (tenant) ID value, Application (client) ID value, Azure AD certificate, certificate password, and Azure environment selection.

  • Azure AD Delegated - Authenticates using a valid Azure AD Directory (tenant) ID value, Application (client) ID value, and Azure environment selection. This type also requires an authorized user to manually enter their SharePoint credentials at runtime.

  • Interactive - Authenticates by requiring an authorized user to manually enter their SharePoint credentials at runtime.

    NOTE: Multi-factor authentication/single sign-on can be bypassed if Windows includes valid authentication session information.
Username Text Yes, if Authentication type is set to Default (Empty) USERNAME="theUserName" The username to use for authenticating to the SharePoint site. This parameter is only required if the Authentication type parameter is set to Default.
Password Text Yes, if Authentication type is set to Default (Empty) PASSWORD="text (encrypted)" The password to use to authenticate with the Username parameter. This parameter is required if the Authentication type parameter is set to Default.
Client ID Text Yes, if Authentication type is set to SharePoint App Only (Empty) CLIENTID="text (encrypted)" The Client ID in SharePoint to use for authentication. This parameter is encrypted in Task Builder. This parameter is required when the Authentication type parameter is set to SharePoint App Only.
Client secret Text Yes, if Authentication type is set to SharePoint App Only (Empty) CLIENTSECRET="text (encrypted)" The Client Secret in SharePoint to use for authentication. This parameter is required if the Authentication type parameter is set to SharePoint App Only.
Azure Tenant ID Text Yes, if Authentication type is set to Azure AD App Only or Azure AD Delegated (Empty) AADTENANTID="text (encrypted)" The Directory (tenant) ID in Azure AD to use for authentication. This parameter is required if the Authentication type parameter is set to Azure AD App Only or Azure AD Delegated.
Azure Client ID Text Yes, if Authentication type is set to Azure AD App Only or Azure AD Delegated (Empty) AADCLIENTID="text (encrypted)" The Application (client) ID in Azure AD to use for authentication. This parameter is required if the Authentication type parameter is set to Azure AD App Only or Azure AD Delegated.
Azure AD certificate Text Yes, if Authentication type is set to Azure AD App Only (Empty) AADCERTIFICATE="certificate.pfx" The Azure AD certificate file (.pfx) to use for authentication. This parameter is required if the Authentication type parameter is set to Azure AD App Only.
Azure AD certificate password Text No (Empty) AADCERTIFICATEPASSWORD="text (encrypted)" The password to use to authenticate with the Azure AD Certificate parameter. This parameter is becomes available when Authentication type is set to Azure AD App Only.
Azure Environment Text (options) Yes, if Authentication type is set to SharePoint App Only, Azure AD App Only, or Azure AD Delegated Azure
  • AZUREENVIRONMENT="azure"
  • AZUREENVIRONMENT="azurechina"
  • AZUREENVIRONMENT="azuregermany"
  • AZUREENVIRONMENT="azureusgovernment"
The Azure environment to use for authentication. The available options are:
  • Azure

  • Azure China

  • Azure Germany

  • Azure US Government

This parameter is required if the Authentication type parameter is set to SharePoint App Only, Azure AD App Only, or Azure AD Delegated.

Refer to these parameters when Version is set to SharePoint 2013 and newer.
Authentication type Text (options) Yes System default
  • AUTHTYPE="basic"
  • AUTHTYPE="form"
  • AUTHTYPE="anonymous"
Specifies the authentication type to use with the connection. Associated parameters vary with each type. The available options are:
  • Default (default)

  • Basic

  • Form

  • Anonymous

Username Text Yes, if Authentication type is set to Basic or Form (Empty) USERNAME="theUserName" The username to use for authenticating to the SharePoint site. This parameter is only required if Authentication type is set to Basic or Form.
Password Text Yes, if Authentication type is set to Basic or Form (Empty) PASSWORD="text (encrypted)" The password to use to authenticate with the Username parameter. This parameter is only required if Authentication type is set to Basic or Form.
Domain Text Yes, if Authentication type is set to Basic or Form (Empty) DOMAIN="myServer" The domain the user belongs to. This parameter is only required if Authentication type is set to Basic or Form.
These parameters are available when Version is set to SharePoint Online or SharePoint 2013 and newer.
Certificate Text No (Empty) CERTIFICATE="C:\Temp\file.cer" The (DER encoded) certificate to use for SharePoint authentication.
Ignore invalid certificate Yes/No No No IGNOREINVALIDCERTIFICATE="yes" If selected, invalid server certificates are automatically ignored. This parameter is disabled by default.
Timeout (seconds) Number No 600 TIMEOUT="500" The number of seconds to wait to connect to the SharePoint server before a timeout error is generated. The default value is 600 seconds.

Connection - Host > Proxy

Property Type Required Default Markup Description
Proxy type Text (options) Yes Default
  • PROXYTYPE="none"
  • PROXYTYPE="http"
The type of proxy required for SharePoint connections that pass through a proxy server. The available options are:
  • System default (default) - Points to the default proxy used by the system.
  • None - No proxy authentication required.
  • HTTP - Proxy type is HTTP.
Use authentication --- No --- --- If enabled, specifies proxy authentication is required, enabling authentication-based parameters (disabled by default). It is active only if Proxy type is set to HTTP.
NOTE: This parameter does not contain markup and is only displayed in visual mode for task construction and configuration purposes.
Proxy server Text No (Empty) PROXYSERVER="proxy.host.com" The hostname (server.domain.com) or IP address (xxx.xxx.xxx.xxx) of the proxy server. This parameter is available only if Proxy type is set to HTTP.
Proxy username Text No (Empty) PROXYUSERNAME="username" The proxy username to authenticate with. This parameter is available only if Use authentication is enabled.
Proxy port Number No 808 PROXYPORT="8080" The port number to use to connect to the proxy server. This parameter is available only if Proxy type is set to HTTP. The default value is 808.
Proxy password Text No (Empty) PROXYPASSWORD="encrypted" The proxy password to authenticate with. This parameter is available only if Use authentication is enabled.

File

Property Type Required Default Markup Description
Remote file(s) Text Yes (Empty)
  • SOURCE="folder/file.txt"
  • SOURCE="folder/*.txt"
  • SOURCE="folder/*.*"
The source files to download. Wildcard characters (for example, *  or ?) may be used to download files matching a certain mask. Multiple files and/or file masks may be specified by separating the entries with the pipe symbol (for example, / source/*.txt|/source/*.bak|/source/*.log).

Click the folder icon to use the SharePoint Browser, a user-friendly interface that enables connection to a SharePoint site in order to view or select specific contents.

Local file(s) Text Yes (Empty)
  • DEST="c:\folder\file.txt"
  • DEST="c:\folder\*.txt"
  • DEST="folder/*.*"
The destination folder of the downloaded files. This requires an absolute path/file name. This can be a fully qualified path or a path and file name. Folders that do not exist will be automatically created at runtime.
Create and populate download dataset Text Yes (Empty) RESULTDATASET="theDownloadInfo" The name of the dataset to create and populate with information regarding the download that took place. For more information, see Datasets.
Source (server relative URL) Text Yes (Empty)
  • URL="folder/file.txt"
  • URL="folder/*.txt"
  • URL="folder/*.*"
The relative URL of the file based on the URL for the server. Click the folder icon to use the SharePoint Browser, a user-friendly interface that enables you to connect to a SharePoint site in order to view or select specific contents.
Destination Text Yes (Empty)
  • DESTINATION="c:\folder\file.txt"
  • DESTINATION="c:\folder\*.txt"
  • DESTINATION="folder/*.*"
The destination folder of the downloaded file. This requires an absolute path/file name. This can be a fully qualified path or a path and file name. Folders that do not exist will be automatically created at runtime.
Overwrite if file exists Yes/No No No OVERWRITE="YES" If selected, a file with the same name as the copied file will be overwritten. If disabled, this step fails with an error if files with the same name are found. This parameter is disabled by default.

File Options

Property Type Required Default Markup Description
Exclude mask Text No (Empty) EXCLUDE="*.txt" Causes this activity to omit any files matching the masks specified. File names or wildcard masks (for example, * or ?) may be used. Multiple entries may be specified by separating them with the pipe (|) symbol (for example, *.txt|*.bak).
Regular expression Yes/No No No RE="YES" If selected, specifies that the value entered in the Exclude mask parameter is interpreted as a regular expression (also referred to as regex or regexp) which provides a concise and flexible means for matching strings of text. If disabled (default) the value is interpreted as plain, readable text.
Only if newer than Date No (Empty) ISNEWERTHAN="%DateSerial(2001,10,12) + TimeSerial(00,00,00)%" If enabled, causes this activity to only act on files that are newer than the date/time specified. Click the Custom button to select from a list of pre-defined date parameters. Enable the Expression option to allow entry of a date/time expression. If this parameter is disabled (default), file "newer than" dates are ignored.
Only if older than Date No (Empty) ISOLDERTHAN="%DateSerial(2001,10,12) + TimeSerial(00,00,00)%" If enabled, causes this action to only act on files that are older than the date/time specified. Click the Custom button to select from a list of pre-defined date parameters. Enable the Expression option to allow entry of a date/time expression. If this parameter is disabled (default), file "older than" dates are ignored.
Overwrite if exists Yes/No No No OVERWRITE="YES" If selected, matching destination files will be overwritten. If disabled, matching files will not be overwritten, however, an error will occur as a result.
Include subfolders Yes/No No No SUBFOLDERS="YES" If selected, specifies that, if present, subfolders should be searched for files matching the mask specified in the Remote files parameter. The default value is NO.
Preserve folder structure Yes/No No No KEEPFOLDERSTRUCT="YES" If selected, specifies that subfolders found in the source folder should be created in the destination folder and source files should be copied into their respective folders rather than directly into the root of the target folder specified in the Local files parameter. The default value is NO. This option is available only if the Include subfolders parameter is selected.

Description

Error Causes

On Error

Additional notes

Datasets

A dataset is a multiple column, multiple row container object where every column represents a particular variable, and each row corresponds to a given member of the dataset in question. This activity creates and populates a dataset containing specific fields (rows) in addition to the standard dataset fields. The table below describes these fields (assuming the dataset name assigned was theDataset).

Name Type Return Value
theDataset.DownloadResult True/False The download result. The value is either True or False.
theDataset.Error Text A textual description of the error that occurred (if any). If no errors occurred during the download step, this dataset will remain empty.
theDataset.LocalFileName Date The local (destination) file name of the file being downloaded.
theDataset.SharePointFileDate Text The current date of the source file being downloaded. The returned date/time format matches the following: MM/DD/YYYY HH:MM:SS AM/PM.
theDataset.SharePointFileName Text The name of the source file being downloaded.
theDataset.SharePointFileSize Text The size (in KB) of the source file being downloaded.

Example

NOTE:
  • Copy and paste the sample AML code below directly into the Task Builder Steps Panel.
  • To successfully run the sample code, update parameters containing user credentials, files, file paths, or other information specific to the task to match your environment.

Description

This sample task demonstrates the use of sessions as well as Automate Desktop's ability to download all files from a SharePoint library and thereafter, delete the empty library.

Copy
<AMSHAREPOINT ACTIVITY="create_session" SITE="https://netauto.sharepoint.com/awesome/site" VERSION="sharepointonline" SPOAUTHTYPE="default" USERNAME="jdoe@netauto.com" PASSWORD="AM5sGnhC7nCfyyeP381FD4KrO+vRJTZvF/awddCvjkraew=aME" SESSION="SharePointSession1" />
<AMSHAREPOINT SESSION="SharePointSession1" DOWNLOADTYPE="multiple" SOURCE="MyLibrary/*.*" DEST="C:\Logs\Download\*.*" RESULTDATASET="downloadDataset" SUBFOLDERS="YES" KEEPFOLDERSTRUCT="YES" />
<AMSHAREPOINT ACTIVITY="delete_list" SESSION="SharePointSession1" LIST="MyLibrary" />
<AMSHAREPOINT ACTIVITY="end_session" SESSION="SharePointSession1" />