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

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0

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

set http = Server.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

set jsonOAuthCC = Server.CreateObject("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")
set sbJson = Server.CreateObject("Chilkat.StringBuilder")
success = http.QuickGetSb("https://graph.microsoft.com/v1.0/sites/SITE_ID/drive/root/children",sbJson)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( http.LastErrorText) & "</pre>"
    Response.End
End If

set json = Server.CreateObject("Chilkat.JsonObject")
success = json.LoadSb(sbJson)

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

numFiles = json.SizeOfArray("d.results")
Response.Write "<pre>" & Server.HTMLEncode( "Number of Files in the SharePoint root folder = " & numFiles) & "</pre>"

i = 0
Do While i < numFiles
    json.I = i

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

    Response.Write "<pre>" & Server.HTMLEncode( i + 1 & ": " & filename) & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( "    Relative URI: " & fileRelativeUri) & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( "    Size in Bytes: " & fileSize) & "</pre>"

    i = i + 1
Loop

'  The output of this program when I tested it:

%>
</body>
</html>