VB.NET UWP/WinRT Dropbox: Dropbox Create Folder

Back to Index

Create a folder. Creates the folder /Halloween/emojis

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

CURL Command

curl -X POST https://api.dropboxapi.com/2/files/create_folder_v2 \
    --header "Authorization: Bearer DROPBOX-ACCESS-TOKEN" \
    --header "Content-Type: application/json" \
    --data "{\"path\": \"/Halloween/emojis\",\"autorename\": false}"

VB.NET UWP/WinRT Example

Dim rest As New Chilkat.Rest
Dim success As Boolean

'  URL: https://api.dropboxapi.com/2/files/create_folder_v2
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","/Halloween/emojis")
json.UpdateBool("autorename",False)

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/create_folder_v2",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 j As Integer
Dim count_j As Integer

Dim metadataName As String = jsonResponse.StringOf("metadata.name")
Dim metadataId As String = jsonResponse.StringOf("metadata.id")
Dim metadataPath_lower As String = jsonResponse.StringOf("metadata.path_lower")
Dim metadataPath_display As String = jsonResponse.StringOf("metadata.path_display")
Dim metadataSharing_infoRead_only As Boolean = jsonResponse.BoolOf("metadata.sharing_info.read_only")
Dim metadataSharing_infoParent_shared_folder_id As String = jsonResponse.StringOf("metadata.sharing_info.parent_shared_folder_id")
Dim metadataSharing_infoTraverse_only As Boolean = jsonResponse.BoolOf("metadata.sharing_info.traverse_only")
Dim metadataSharing_infoNo_access As Boolean = jsonResponse.BoolOf("metadata.sharing_info.no_access")
i = 0
count_i = jsonResponse.SizeOfArray("metadata.property_groups")
While i < count_i
    jsonResponse.I = i
    Dim template_id As String = jsonResponse.StringOf("metadata.property_groups[i].template_id")
    j = 0
    count_j = jsonResponse.SizeOfArray("metadata.property_groups[i].fields")
    While j < count_j
        jsonResponse.J = j
        Dim name As String = jsonResponse.StringOf("metadata.property_groups[i].fields[j].name")
        Dim value As String = jsonResponse.StringOf("metadata.property_groups[i].fields[j].value")
        j = j + 1
    End While
    i = i + 1
End While

Sample JSON Response Body

{
  "metadata": {
    "name": "emojis",
    "id": "id:a4ayc_80_OEAAAAAAAAAXz",
    "path_lower": "/halloween/emojis",
    "path_display": "/Halloween/emojis",
    "sharing_info": {
      "read_only": false,
      "parent_shared_folder_id": "84528192421",
      "traverse_only": false,
      "no_access": false
    },
    "property_groups": [
      {
        "template_id": "ptid:1a5n2i6d3OYEAAAAAAAAAYa",
        "fields": [
          {
            "name": "Security Policy",
            "value": "Confidential"
          }
        ]
      }
    ]
  }
}