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

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoHttp
OAuthCC    Handle hoJsonOAuthCC
    Variant vSbJson
    Handle hoSbJson
    Handle hoJson
    Integer iNumFiles
    Integer i
    String sFilename
    String sFileRelativeUri
    Integer iFileSize
    String sTemp1

    Move False To iSuccess

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

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

    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonOAuthCC
    If (Not(IsComObjectCreated(hoJsonOAuthCC))) Begin
        Send CreateComObject of hoJsonOAuthCC
    End
    Get ComUpdateString Of hoJsonOAuthCC "client_id" "CLIENT_ID" To iSuccess
    Get ComUpdateString Of hoJsonOAuthCC "client_secret" "SECRET_VALUE" To iSuccess
    Get ComUpdateString Of hoJsonOAuthCC "scope" "https://graph.microsoft.com/.default" To iSuccess
    Get ComUpdateString Of hoJsonOAuthCC "token_endpoint" "https://login.microsoftonline.com/TENANT_ID/oauth2/v2.0/token" To iSuccess

    Get ComEmit Of hoJsonOAuthCC To sTemp1
    Set ComAuthToken Of hoHttp To sTemp1
    //  --------------------------------------------------------------------------------------------------------

    //  Indicate that we want a JSON reply
    Set ComAccept Of hoHttp To "application/json;odata=verbose"

    Get ComSetUrlVar Of hoHttp "sharepoint_hostname" "example.sharepoint.com" To iSuccess
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbJson
    If (Not(IsComObjectCreated(hoSbJson))) Begin
        Send CreateComObject of hoSbJson
    End
    Get pvComObject of hoSbJson to vSbJson
    Get ComQuickGetSb Of hoHttp "https://graph.microsoft.com/v1.0/sites/SITE_ID/drive/root/children" vSbJson To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get pvComObject of hoSbJson to vSbJson
    Get ComLoadSb Of hoJson vSbJson To iSuccess

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

    Get ComSizeOfArray Of hoJson "d.results" To iNumFiles
    Showln "Number of Files in the SharePoint root folder = " iNumFiles

    Move 0 To i
    While (i < iNumFiles)
        Set ComI Of hoJson To i

        Get ComStringOf Of hoJson "d.results[i].Name" To sFilename
        Get ComStringOf Of hoJson "d.results[i].ServerRelativeUrl" To sFileRelativeUri
        Get ComIntOf Of hoJson "d.results[i].Length" To iFileSize

        Showln (i + 1) ": " sFilename
        Showln "    Relative URI: " sFileRelativeUri
        Showln "    Size in Bytes: " iFileSize

        Move (i + 1) To i
    Loop

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


End_Procedure