README Search OneDrive

README Search Files (Drive API) #

Overview #

Searches for files in the signed-in user’s OneDrive for Business using the Drive search endpoint. Authentication is via OAuth2 with MFA support using VBAuth.dll. SharePoint document libraries are not included — this endpoint searches OneDrive only.

Two search modes are available via radio button: Name only (client-side filter on filename) and Name and content (all server results displayed). Folders are excluded from results client-side.

Results display filename, last modified date, last modified by, and the web URL of each file. Up to 25 results are returned per search.

Office apps #

  • Access (tested M365)
  • Excel (untested M365)

Required components #

  • VBAuth.dll v1.x
  • modVBAuthGlobalConstants.bas (from /shared)
  • modSearchFilesDriveAPI.bas (this module)

Azure Entra App Registration #

Delegated permissions:

  • Files.Read

Admin consent is required before users can authenticate.

VBAuth Admin Table – Required Values #

Column NameRequired Value / ExampleNotes
AppID27Identifies this feature’s configuration record
ActionNameVBAuth – Search Files (Drive API)Display name — any value acceptable
ClientID(your App Client ID)GUID from Azure App Registration Overview blade
TenantID(your Tenant ID)GUID from Azure App Registration Overview blade
ObjectID(your Object ID)Set by PopulateMissingObjectIDs
ScopeClaimsFiles.ReadComma-separated Graph scopes
VerbGETHTTP method
URLPart1https://graph.microsoft.com/v1.0/me/drive/root/search(q='')Base endpoint — search term embedded at runtime by the module
URLParameter1NO VALUE REQUIREDNot used
URLPart2NO VALUE REQUIREDNot used
URLParameter2NO VALUE REQUIREDNot used
URLPart3NO VALUE REQUIREDNot used
WaitForLogin60Seconds — NB MSXML2 timeout parameters are in milliseconds

Note: the module builds the full URL at runtime, embedding the search term directly in the function call syntax (search(q='term')?$top=25...). URLPart1 is stored for documentation purposes only and is not used for URL assembly by SetEntraAPPIdValues.

Module: modSearchFilesDriveAPI.bas #

Public functions #

Public Function SearchFilesDriveAPI( _
    ByVal strTerm As String, _
    ByVal intSearchMode As Integer, _
    ByRef strResult As String, _
    ByRef strMessage As String) As Boolean
Code language: JavaScript (javascript)

Calls GET /me/drive/root/search(q='{term}')?$top=25 with $select to limit response size. intSearchMode 1 = name only (client-side filter), 2 = name and content. Folders are excluded client-side. Returns True on success. strResult receives the formatted display text. strMessage receives a summary on success or error description on failure.

Private functions #

  • SafeString — returns a string field from a parsed JSON Dictionary, returning "" for absent fields without error.
  • IsFolder — returns True if the driveItem has a folder key, indicating it is a folder rather than a file.

Behaviour #

  • Runs as the signed-in user (delegated permissions).
  • HTTP 200 is the success code.
  • Results are from the signed-in user’s OneDrive for Business only. SharePoint document libraries are not included.
  • Name only mode: the server returns up to 25 matches (name and content), then only items whose filename contains the search term are kept client-side. The displayed count may therefore be less than 25.
  • Name and content mode: all server results up to 25 are displayed.
  • Folders are excluded client-side by checking for the folder key in each driveItem.
  • If @odata.nextLink is present in the response, more results are available and a note is appended to the output.
  • Authentication is interactive on first run; subsequent calls within the session reuse the cached token.

Notes #

  • Files.Read is the minimum required scope for this endpoint.
  • Admin consent is required before users can authenticate.
  • The Drive API search endpoint (GET /me/drive/root/search) is a legacy endpoint. Microsoft has indicated that the Search API (POST /search/query) is preferred for new development, but the Drive API remains supported on v1.0.
  • This feature uses a separate Entra app registration from the Search API feature (AppID 26) so that a developer taking only this feature uses the correct minimum scope (Files.Read rather than Files.Read.All).

VBAuth, developed and maintained by Andrew Richards (The IT Service Ltd) and Peter Bryant (Corylus Business Systems), © 2025–2026. All rights reserved. https://vbauth.com

Updated on April 3, 2026