Sample code for 30+ languages & platforms
Visual FoxPro 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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loHttp
LOCAL loJsonOAuthCC
LOCAL loSbJson
LOCAL loJson
LOCAL lnNumFiles
LOCAL i
LOCAL lcFilename
LOCAL lcFileRelativeUri
LOCAL lnFileSize

lnSuccess = 0

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

loHttp = CreateObject('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

loJsonOAuthCC = CreateObject('Chilkat.JsonObject')
loJsonOAuthCC.UpdateString("client_id","CLIENT_ID")
loJsonOAuthCC.UpdateString("client_secret","SECRET_VALUE")
loJsonOAuthCC.UpdateString("scope","https://graph.microsoft.com/.default")
loJsonOAuthCC.UpdateString("token_endpoint","https://login.microsoftonline.com/TENANT_ID/oauth2/v2.0/token")

loHttp.AuthToken = loJsonOAuthCC.Emit()
*  --------------------------------------------------------------------------------------------------------

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

loHttp.SetUrlVar("sharepoint_hostname","example.sharepoint.com")
loSbJson = CreateObject('Chilkat.StringBuilder')
lnSuccess = loHttp.QuickGetSb("https://graph.microsoft.com/v1.0/sites/SITE_ID/drive/root/children",loSbJson)
IF (lnSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loJsonOAuthCC
    RELEASE loSbJson
    CANCEL
ENDIF

loJson = CreateObject('Chilkat.JsonObject')
loJson.LoadSb(loSbJson)

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

lnNumFiles = loJson.SizeOfArray("d.results")
? "Number of Files in the SharePoint root folder = " + STR(lnNumFiles)

i = 0
DO WHILE i < lnNumFiles
    loJson.I = i

    lcFilename = loJson.StringOf("d.results[i].Name")
    lcFileRelativeUri = loJson.StringOf("d.results[i].ServerRelativeUrl")
    lnFileSize = loJson.IntOf("d.results[i].Length")

    ? STR(i + 1) + ": " + lcFilename
    ? "    Relative URI: " + lcFileRelativeUri
    ? "    Size in Bytes: " + STR(lnFileSize)

    i = i + 1
ENDDO

*  The output of this program when I tested it:

RELEASE loHttp
RELEASE loJsonOAuthCC
RELEASE loSbJson
RELEASE loJson