OneDrive/SharePoint — List files
OneDrive/SharePoint — List files
Section titled “OneDrive/SharePoint — List files”Type: msfiles-list · Package: OneDrive / SharePoint v1.0.5 · Output: List<Dictionary<string,object>>
Lists a folder’s content or searches files by text across the whole drive. It is the usual way to get the IDs the other activities need.
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.
It has two modes:
- List a folder (
folderId, the drive root by default): returns the files and subfolders directly inside it, without going into subfolders. - Search (
query): searches the text in names and content of the files across the whole drive, subfolders included. If you givequery, it takes precedence overfolderId.
Keep in mind:
- It returns at most
maxResultsitems, from a single page of Microsoft Graph results: for very large folders it may return fewer than the total. If you need to go through many files, organize them in subfolders and list each one. - Search uses the Microsoft 365 index: a freshly uploaded file can take a few minutes to show up.
- The order of results is decided by Microsoft 365; if you need a specific order, sort them afterwards.
- It is read-only.
Required parameters
Section titled “Required parameters”None.
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
session | ZoanMicrosoftFilesSession | — | Connect session. Inherited inside Connect’s body. |
folderId | string | — | ID of the folder to list. When omitted, the drive root. Ignored when query is set. |
query | string | — | Text to search for across the drive (name and content). When set, it overrides folderId. |
maxResults | int | 100 | Maximum number of items. Non-numeric, 0 or negative values use 100. |
Output
Section titled “Output”Returns a List<Dictionary<string,object>>: each item is a file or folder with the keys id, name, isFolder, size, webUrl, parentId, modifiedTime, createdTime and childCount (detail in OneDrive & SharePoint Activities). Loop over it with a For each and access by key (item["name"], item["id"]).
If the folder is empty or the search finds nothing, it returns an empty list (results.Count == 0), not an error.
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. |
itemNotFound (Microsoft Graph, 404) | There is no folder with that folderId in the session’s drive. |
accessDenied (Microsoft Graph, 403) | The connection has no read permission on the drive or folder. |
Example
Section titled “Example”Download only the PDFs in a folder:
OneDrive/SharePoint — Connect credential = credential("m365-operations") └─ body: OneDrive/SharePoint — List files folderId = invoicesFolderId → output: files For each f in files └─ If condition = !(bool)f["isFolder"] && f["name"].ToString().EndsWith(".pdf") └─ then: OneDrive/SharePoint — Download id = f["id"] destination = "C:\invoices"Related activities
Section titled “Related activities”- OneDrive/SharePoint — Get info — data of a specific item.
- OneDrive/SharePoint — Download — download a file.
- OneDrive/SharePoint — Connect — open the session.
- All OneDrive / SharePoint activities