OneDrive/SharePoint — Download
OneDrive/SharePoint — Download
Section titled “OneDrive/SharePoint — Download”Type: msfiles-download · Package: OneDrive / SharePoint v1.0.5 · Output: string
Downloads a file from the drive to the machine. Optionally, it exports Office documents to PDF (Word, Excel, PowerPoint) while downloading them, with no need for Office on the robot’s machine.
How it works
Section titled “How it works”It works on the session created with OneDrive/SharePoint — Connect. Pass it in the session parameter, or place this activity inside the body of Connect to inherit it automatically.
Give the file by its id (from List files). The activity:
- Looks up the file name in the cloud (with
asPdf, it changes its extension to.pdf). - Decides the local path: if
destinationis a folder that already exists, it saves the file inside with its original name; otherwise it takesdestinationas a file path and creates any missing folders. - Downloads the content (or the PDF conversion made by Microsoft 365) and writes it to disk.
Keep in mind:
- If a local file with that name already exists, it is overwritten.
- If you want to download into a folder, make sure it exists: a folder path that does not exist is treated as a file name (
C:\downloadsnot yet created would produce a file calleddownloads). asPdfworks with the formats Microsoft 365 can convert (Word, Excel, PowerPoint documents and similar); with others, Microsoft Graph returns an error.- It does not modify the file in the cloud.
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
id | string | — | ID of the file in the drive. |
destination | string | — | Local target file path, or an existing folder (the file name is used). |
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
session | ZoanMicrosoftFilesSession | — | Connect session. Inherited inside Connect’s body. |
asPdf | bool | false | Export the file to PDF (Office documents). The saved file has the .pdf extension. |
Output
Section titled “Output”Returns a string with the full path of the saved file (with the .pdf extension if you used asPdf and destination was a folder). Assign it to a variable to open, attach or process it later.
Common errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
No OneDrive/SharePoint session available. Provide 'session' from an msfiles-connect activity, or place this activity inside the Connect activity's body so the session is inherited automatically. | The activity is outside Connect’s body and did not receive session. Place it inside the body or pass session = session. |
'id' is required. / 'destination' is required. | The parameter is empty or its expression returned null. |
itemNotFound (Microsoft Graph, 404) | There is no file with that ID in the session’s drive. |
No content returned. | Microsoft Graph replied without content. Retry; if it persists, check that the ID belongs to a file and not a folder (with Get info, isFolder). |
Microsoft Graph conversion error (notSupported or 406) | With asPdf, the file format cannot be converted to PDF. Download it without asPdf. |
Access to the path '…' is denied. | The robot’s account cannot write to the local folder, or the file is open in another program. |
Example
Section titled “Example”OneDrive/SharePoint — Connect credential = credential("m365-operations") └─ body: OneDrive/SharePoint — List files query = "Contract" → output: found OneDrive/SharePoint — Download id = found[0]["id"] destination = "C:\downloads" asPdf = true → output: path Log message = "Saved to " + pathRelated activities
Section titled “Related activities”- OneDrive/SharePoint — Upload — upload a file.
- OneDrive/SharePoint — List files — locate the file and its ID.
- OneDrive/SharePoint — Get info — see the file’s data.
- All OneDrive / SharePoint activities