Skip to content

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.

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:

  1. Looks up the file name in the cloud (with asPdf, it changes its extension to .pdf).
  2. Decides the local path: if destination is a folder that already exists, it saves the file inside with its original name; otherwise it takes destination as a file path and creates any missing folders.
  3. 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:\downloads not yet created would produce a file called downloads).
  • asPdf works 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.
ParameterTypeDefaultDescription
idstring—ID of the file in the drive.
destinationstring—Local target file path, or an existing folder (the file name is used).
ParameterTypeDefaultDescription
sessionZoanMicrosoftFilesSession—Connect session. Inherited inside Connect’s body.
asPdfboolfalseExport the file to PDF (Office documents). The saved file has the .pdf extension.

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.

MessageCause 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.
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 " + path