AutoIt
AutoIt
SharePoint Get Files in Root Folder
See more SharePoint Examples
Gets the list of files that exist in the root folder.Chilkat AutoIt Downloads
Local $bSuccess = False
; This requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oHttp = ObjCreate("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
$oJsonOAuthCC = ObjCreate("Chilkat.JsonObject")
$oJsonOAuthCC.UpdateString("client_id","CLIENT_ID")
$oJsonOAuthCC.UpdateString("client_secret","SECRET_VALUE")
$oJsonOAuthCC.UpdateString("scope","https://graph.microsoft.com/.default")
$oJsonOAuthCC.UpdateString("token_endpoint","https://login.microsoftonline.com/TENANT_ID/oauth2/v2.0/token")
$oHttp.AuthToken = $oJsonOAuthCC.Emit()
; --------------------------------------------------------------------------------------------------------
; Indicate that we want a JSON reply
$oHttp.Accept = "application/json;odata=verbose"
$oHttp.SetUrlVar("sharepoint_hostname","example.sharepoint.com")
$oSbJson = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oHttp.QuickGetSb("https://graph.microsoft.com/v1.0/sites/SITE_ID/drive/root/children",$oSbJson)
If ($bSuccess = False) Then
ConsoleWrite($oHttp.LastErrorText & @CRLF)
Exit
EndIf
$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.LoadSb($oSbJson)
; Iterate over the results and get each file's name, size, and last-modified date/time.
Local $iNumFiles = $oJson.SizeOfArray("d.results")
ConsoleWrite("Number of Files in the SharePoint root folder = " & $iNumFiles & @CRLF)
Local $i = 0
While $i < $iNumFiles
$oJson.I = $i
Local $sFilename = $oJson.StringOf("d.results[i].Name")
Local $sFileRelativeUri = $oJson.StringOf("d.results[i].ServerRelativeUrl")
Local $iFileSize = $oJson.IntOf("d.results[i].Length")
ConsoleWrite(($i + 1) & ": " & $sFilename & @CRLF)
ConsoleWrite(" Relative URI: " & $sFileRelativeUri & @CRLF)
ConsoleWrite(" Size in Bytes: " & $iFileSize & @CRLF)
$i = $i + 1
Wend
; The output of this program when I tested it: