Sample code for 30+ languages & platforms
Xojo Plugin Requires Chilkat v11.0.0+

SharePoint Get Files in Root Folder

See more SharePoint Examples

Gets the list of files that exist in the root folder.

Chilkat Xojo Plugin Downloads

Xojo Plugin
Dim success As Boolean
success = False

//  This requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

Dim http As New Chilkat.Http

//  --------------------------------------------------------------------------------------------------------
//  Provide the information needed for Chilkat to automatically fetch the OAuth2.0 access token as needed.

//  To create your App Registration for SharePoint in Azure Entra ID,
//  see How to Create SharePoint App Registration for OAuth 2.0 Client Credentials

Dim jsonOAuthCC As New Chilkat.JsonObject
success = jsonOAuthCC.UpdateString("client_id","CLIENT_ID")
success = jsonOAuthCC.UpdateString("client_secret","SECRET_VALUE")
success = jsonOAuthCC.UpdateString("scope","https://graph.microsoft.com/.default")
success = jsonOAuthCC.UpdateString("token_endpoint","https://login.microsoftonline.com/TENANT_ID/oauth2/v2.0/token")

http.AuthToken = jsonOAuthCC.Emit()
//  --------------------------------------------------------------------------------------------------------

//  Indicate that we want a JSON reply
http.Accept = "application/json;odata=verbose"

success = http.SetUrlVar("sharepoint_hostname","example.sharepoint.com")
Dim sbJson As New Chilkat.StringBuilder
success = http.QuickGetSb("https://graph.microsoft.com/v1.0/sites/SITE_ID/drive/root/children",sbJson)
If (success = False) Then
    System.DebugLog(http.LastErrorText)
    Return
End If

Dim json As New Chilkat.JsonObject
success = json.LoadSb(sbJson)

//  Iterate over the results and get each file's name, size, and last-modified date/time.

Dim numFiles As Int32
numFiles = json.SizeOfArray("d.results")
System.DebugLog("Number of Files in the SharePoint root folder = " + Str(numFiles))

Dim i As Int32
i = 0
While i < numFiles
    json.I = i

    Dim filename As String
    filename = json.StringOf("d.results[i].Name")
    Dim fileRelativeUri As String
    fileRelativeUri = json.StringOf("d.results[i].ServerRelativeUrl")
    Dim fileSize As Int32
    fileSize = json.IntOf("d.results[i].Length")

    System.DebugLog(Str(i + 1) + ": " + filename)
    System.DebugLog("    Relative URI: " + fileRelativeUri)
    System.DebugLog("    Size in Bytes: " + Str(fileSize))

    i = i + 1
Wend

//  The output of this program when I tested it: