VB.NET UWP/WinRT Dropbox: Dropbox List Contents of Folder

Back to Index

Starts returning the contents of a folder. If the result's ListFolderResult.has_more field is true, call list_folder/continue with the returned ListFolderResult.cursor to retrieve more entries.

Documentation: https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder

CURL Command

curl -X POST https://api.dropboxapi.com/2/files/list_folder \
    --header "Authorization: Bearer DROPBOX-ACCESS-TOKEN" \
    --header "Content-Type: application/json" \
    --data "{\"path\": \"/Homework/math\",\"recursive\": false,\"include_media_info\": false,\"include_deleted\": false,\"include_has_explicit_shared_members\": false,\"include_mounted_folders\": true}"

VB.NET UWP/WinRT Example

Dim rest As New Chilkat.Rest
Dim success As Boolean

'  URL: https://api.dropboxapi.com/2/files/list_folder
Dim bTls As Boolean = True
Dim port As Integer = 443
Dim bAutoReconnect As Boolean = True
success = Await rest.ConnectAsync("api.dropboxapi.com",port,bTls,bAutoReconnect)
If (success <> True) Then
    Debug.WriteLine("ConnectFailReason: " & rest.ConnectFailReason)
    Debug.WriteLine(rest.LastErrorText)
    Exit Sub
End If


'  See the Online Tool for Generating JSON Creation Code
Dim json As New Chilkat.JsonObject
json.UpdateString("path","/Homework/math")
json.UpdateBool("recursive",False)
json.UpdateBool("include_media_info",False)
json.UpdateBool("include_deleted",False)
json.UpdateBool("include_has_explicit_shared_members",False)
json.UpdateBool("include_mounted_folders",True)

rest.AddHeader("Authorization","Bearer DROPBOX-ACCESS-TOKEN")
rest.AddHeader("Content-Type","application/json")

Dim sbRequestBody As New Chilkat.StringBuilder
json.EmitSb(sbRequestBody)
Dim sbResponseBody As New Chilkat.StringBuilder
success = Await rest.FullRequestSbAsync("POST","/2/files/list_folder",sbRequestBody,sbResponseBody)
If (success <> True) Then
    Debug.WriteLine(rest.LastErrorText)
    Exit Sub
End If

Dim respStatusCode As Integer = rest.ResponseStatusCode
If (respStatusCode >= 400) Then
    Debug.WriteLine("Response Status Code = " & respStatusCode)
    Debug.WriteLine("Response Header:")
    Debug.WriteLine(rest.ResponseHeader)
    Debug.WriteLine("Response Body:")
    Debug.WriteLine(sbResponseBody.GetAsString())
    Exit Sub
End If


Dim jsonResponse As New Chilkat.JsonObject
jsonResponse.LoadSb(sbResponseBody)

'  See the Online Tool for Generating JSON Parse Code
Dim i As Integer
Dim count_i As Integer

Dim cursor As String = jsonResponse.StringOf("cursor")
Dim has_more As Boolean = jsonResponse.BoolOf("has_more")
i = 0
count_i = jsonResponse.SizeOfArray("entries")
While i < count_i
    jsonResponse.I = i
    Dim Tag As String = jsonResponse.StringOf("entries[i]."".tag""")
    Dim name As String = jsonResponse.StringOf("entries[i].name")
    Dim path_lower As String = jsonResponse.StringOf("entries[i].path_lower")
    Dim path_display As String = jsonResponse.StringOf("entries[i].path_display")
    Dim id As String = jsonResponse.StringOf("entries[i].id")
    Dim client_modified As String = jsonResponse.StringOf("entries[i].client_modified")
    Dim server_modified As String = jsonResponse.StringOf("entries[i].server_modified")
    Dim rev As String = jsonResponse.StringOf("entries[i].rev")
    Dim size As Integer = jsonResponse.IntOf("entries[i].size")
    Dim content_hash As String = jsonResponse.StringOf("entries[i].content_hash")
    i = i + 1
End While

Sample JSON Response Body

{
  "entries": [
    {
      ".tag": "file",
      "name": "Matrices.txt",
      "path_lower": "/homework/math/matrices.txt",
      "path_display": "/Homework/math/Matrices.txt",
      "id": "id:qk7WwvROeSAAAAAAAAAAAQ",
      "client_modified": "2016-06-02T20:41:02Z",
      "server_modified": "2016-06-02T20:41:03Z",
      "rev": "5482db15f",
      "size": 6,
      "content_hash": "5a3c776e2631edabe2ba710ac72301b3aeca821ba4f7d36b56cc6050ea6c2ba8"
    },
    {
      ".tag": "file",
      "name": "Document.docx",
      "path_lower": "/homework/math/document.docx",
      "path_display": "/Homework/math/Document.docx",
      "id": "id:JSXYsxHo1hAAAAAAAAAABw",
      "client_modified": "2018-10-22T21:59:23Z",
      "server_modified": "2018-10-22T21:59:23Z",
      "rev": "10482db15f",
      "size": 11009,
      "content_hash": "ab9c1887a653a8f42e4401425ac02839e1f76533e1d44ac8d0605d870a16c25d"
    }
  ],
  "cursor": "AAHnmmjY1IztwebFmkByuZ_Vgzz-tSYXYE3KhdkUxBfETpGjPqTBz7ZzBj1G7zkPPVanKCt0FtzqXjDQ2ggQKYZTiL4mJ346fRelmP049QjN5CZzeMHbD_lSFqA96Br36vR9YLg40VAHu42TcCG38MbUPOCKa-wdguu5C1JsgYvIaXIcjRMCfbxz98JdYhhefmu0pjoxtgtCstOrmp_pXIng",
  "has_more": false
}