DownloadFile
Retrieves and downloads a specified file from OneDrive storage to the local or application context.
Stored Procedure Specific Information
Microsoft OneDrive allows only a small subset of columns to be used in the Exec query. Either ResourcePath or ResourceId is required to download the file. Typically, these columns can only be used with the = comparison.
If the file is present in the root folder of a OneDrive account, mention the file name directly for the value of ResourcePath.
For example:
EXECUTE DownloadFile ResourcePath = 'Book.xlsx', LocalFile = 'D:\\Desktop\\Book.xlsx'
If the file is present inside a child folder of a OneDrive account, you need to specify the path of the file, starting from the child folder name, for the value of ResourcePath.
For example:
EXECUTE DownloadFile ResourcePath = 'Notebooks/test.png', LocalFile = 'D:\\Desktop\\test.png'
You can also download the file by providing the file's ResourceId.
For example:
EXECUTE DownloadFile ResourceId = '01CYQN2MFPR6NIWVZNMNFL3SL4E3KF7IHY', LocalFile = 'D:\\Desktop\\test.png'
Input
| Name | Type | Required | Accepts Output Streams | Description |
| ResourcePath | String | False | False | Path to the file resource to be downloaded. Either ResourcePath or ResourceId must be provided to locate the file. |
| ResourceId | String | False | False | Unique identifier of the file to download. Either ResourceId or ResourcePath must be provided. |
| DriveId | String | False | False | ID of the drive containing the resource. Required only if the resource is in a drive other than the current user's default drive. |
| LocalFile | String | False | False | Local file system path, including the file name, where the downloaded file should be saved. Leave empty to return the file content in memory instead. |
| Encoding | String | False | False | Specifies the encoding format for the downloaded file content if returned in memory. Applies only when LocalFile is left empty.
The allowed values are NONE, BASE64. The default value is BASE64. |
| Overwrite | String | False | False | Set to 'true' to overwrite an existing file at the specified LocalFile path. If 'false', the download fails if the file already exists. |
| FileStream | String | False | True | An active output stream instance to which the file data should be written. Used only if LocalFile is not specified. |
| Version | String | False | False | Specifies a particular version of the file to download. Leave blank to download the latest version. |
| UserId | String | False | False | ID of the user who created the file version. Required only when downloading a specific version. |
Result Set Columns
| Name | Type | Description |
| FileData | String | Returns the file content as a byte stream or encoded string if LocalFile is empty. Format depends on the specified Encoding input. |
| Success | String | Indicates whether the file was downloaded successfully. Returns success status or error details. |