VB.NET UWP/WinRT Dropbox: Dropbox Delete a File

Back to Index

Deletes a file on Dropbox

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

CURL Command

curl -X POST https://api.dropboxapi.com/2/files/delete_v2 \
    --header "Authorization: Bearer DROPBOX-ACCESS-TOKEN" \
    --header "Content-Type: application/json" \
    --data "{\"path\": \"/Homework/math/Prime_Numbers.txt\"}"

VB.NET UWP/WinRT Example

Dim rest As New Chilkat.Rest
Dim success As Boolean

'  URL: https://api.dropboxapi.com/2/files/delete_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","/Homework/math/Prime_Numbers.txt")

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/delete_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 metadataTag As String = jsonResponse.StringOf("metadata."".tag""")
Dim metadataName As String = jsonResponse.StringOf("metadata.name")
Dim metadataId As String = jsonResponse.StringOf("metadata.id")
Dim metadataClient_modified As String = jsonResponse.StringOf("metadata.client_modified")
Dim metadataServer_modified As String = jsonResponse.StringOf("metadata.server_modified")
Dim metadataRev As String = jsonResponse.StringOf("metadata.rev")
Dim metadataSize As Integer = jsonResponse.IntOf("metadata.size")
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_infoModified_by As String = jsonResponse.StringOf("metadata.sharing_info.modified_by")
Dim metadataHas_explicit_shared_members As Boolean = jsonResponse.BoolOf("metadata.has_explicit_shared_members")
Dim metadataContent_hash As String = jsonResponse.StringOf("metadata.content_hash")
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": {
    ".tag": "file",
    "name": "Prime_Numbers.txt",
    "id": "id:a4ayc_80_OEAAAAAAAAAXw",
    "client_modified": "2015-05-12T15:50:38Z",
    "server_modified": "2015-05-12T15:50:38Z",
    "rev": "a1c10ce0dd78",
    "size": 7212,
    "path_lower": "/homework/math/prime_numbers.txt",
    "path_display": "/Homework/math/Prime_Numbers.txt",
    "sharing_info": {
      "read_only": true,
      "parent_shared_folder_id": "84528192421",
      "modified_by": "dbid:AAH4f99T0taONIb-OurWxbNQ6ywGRopQngc"
    },
    "property_groups": [
      {
        "template_id": "ptid:1a5n2i6d3OYEAAAAAAAAAYa",
        "fields": [
          {
            "name": "Security Policy",
            "value": "Confidential"
          }
        ]
      }
    ],
    "has_explicit_shared_members": false,
    "content_hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
  }
}