VB.NET UWP/WinRT Dropbox: Dropbox Copy a File or Folder

Back to Index

Copy a file or folder to a different location in the user's Dropbox. If the source path is a folder all its contents will be copied.

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

CURL Command

curl -X POST https://api.dropboxapi.com/2/files/copy_v2 \
    --header "Authorization: Bearer DROPBOX-ACCESS-TOKEN" \
    --header "Content-Type: application/json" \
    --data "{\"from_path\": \"/ocean/starfish.jpg\",\"to_path\": \"/ocean/starfish2.jpg\",\"allow_shared_folder\": false,\"autorename\": false,\"allow_ownership_transfer\": false}"

VB.NET UWP/WinRT Example

Dim rest As New Chilkat.Rest
Dim success As Boolean

'  URL: https://api.dropboxapi.com/2/files/copy_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("from_path","/ocean/starfish.jpg")
json.UpdateString("to_path","/ocean/starfish2.jpg")
json.UpdateBool("allow_shared_folder",False)
json.UpdateBool("autorename",False)
json.UpdateBool("allow_ownership_transfer",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/copy_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 metadataTag As String = jsonResponse.StringOf("metadata."".tag""")
Dim metadataName As String = jsonResponse.StringOf("metadata.name")
Dim metadataPath_lower As String = jsonResponse.StringOf("metadata.path_lower")
Dim metadataPath_display As String = jsonResponse.StringOf("metadata.path_display")
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 metadataContent_hash As String = jsonResponse.StringOf("metadata.content_hash")

Sample JSON Response Body

{
  "metadata": {
    ".tag": "file",
    "name": "starfish2.jpg",
    "path_lower": "/ocean/starfish2.jpg",
    "path_display": "/ocean/starfish2.jpg",
    "id": "id:JSXYsxHo1hAAAAAAAAAADg",
    "client_modified": "2018-10-22T22:38:18Z",
    "server_modified": "2018-10-22T22:40:38Z",
    "rev": "1c482db15f",
    "size": 6229,
    "content_hash": "9fa9d692d0762ee759c22dea993c7de0068f9ba2ca842e761a1636d3b0b3cbba"
  }
}