Skip to content

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.

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 give query, it takes precedence over folderId.

Keep in mind:

  • It returns at most maxResults items, 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.

None.

ParameterTypeDefaultDescription
sessionZoanMicrosoftFilesSession—Connect session. Inherited inside Connect’s body.
folderIdstring—ID of the folder to list. When omitted, the drive root. Ignored when query is set.
querystring—Text to search for across the drive (name and content). When set, it overrides folderId.
maxResultsint100Maximum number of items. Non-numeric, 0 or negative values use 100.

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.

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.
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.

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"