Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
snaidamast
6 years agoExplorer | Level 3
DropBox API Async Call, "DropBoxClient.Files.DownloadAsync" will not throw an exception (solution)
Issue: I have been using DropBox for the storage of my new document management application's installation file as well as for updated, individual files that can be downloaded at a later date (after ...
snaidamast
6 years agoExplorer | Level 3
Here is my code...
Private Async Sub Dropbox_DownloadApplicationFiles(ByVal poDropboxMethodDataStructure As DropboxMethodDataStructure)
Dim liResult As Integer = 0
Dim lsApplicationDirectory As String = My.Application.Info.DirectoryPath + "\"
Dim loFileByteArray As Object
Dim loDropboxMethodDataStructure As New DropboxMethodDataStructure()
Dim loDropBoxClient As DropboxClient
Dim loDropBoxClientResponse As Object
Try
loDropboxMethodDataStructure.RESULT = 0
loDropBoxClient = New DropboxClient(csDropBoxUserAccessToken)
For Each lsFileName As String In poDropboxMethodDataStructure.FILE_NAMES_ARRAYLIST
' test for existence of dropbox file (if file not found (path not found error), this async call will throw an exception
loDropBoxClientResponse = Await loDropBoxClient.Files.GetMetadataAsync("/CDOCS" + "/" + lsFileName)
' download dropbox file (this async call will NOT throw an exception
loDropBoxClientResponse = Await loDropBoxClient.Files.DownloadAsync("/CDOCS" + "/" + lsFileName)
' write dropbox file to application directory
loFileByteArray = Await loDropBoxClientResponse.GetContentAsByteArrayAsync()
System.IO.File.WriteAllBytes(lsApplicationDirectory + "\" + lsFileName, loFileByteArray)
' TESTING ONLY !!!
If (lsFileName.Equals("CDOCS.exe")) Then
Exit For
End If
Next
Catch loDropboxException As DropboxException
loDropboxMethodDataStructure.RESULT = -2
loDropboxMethodDataStructure.METHOD_MESSAGE = "APPLICATION UPDATE ERROR!!! (Method: Dropbox_DownloadApplicationFiles): " + loDropboxException.Message + Environment.NewLine + Environment.NewLine + "Please contact Black Falcon Software..."
Catch loException As Exception
loDropboxMethodDataStructure.RESULT = -1
loDropboxMethodDataStructure.METHOD_MESSAGE = "APPLICATION UPDATE ERROR!!! (Method: Dropbox_DownloadApplicationFiles): " + loException.Message + Environment.NewLine + Environment.NewLine + "Please contact Black Falcon Software..."
End Try
liResult = loDropboxMethodDataStructure.RESULT
If (liResult < 0) Then
Console.WriteLine("")
Console.WriteLine("")
Console.WriteLine("")
Console.WriteLine("--------------")
Console.WriteLine("-- ERROR!!! --")
Console.WriteLine("--------------")
Console.WriteLine(loDropboxMethodDataStructure.METHOD_MESSAGE)
Console.WriteLine("--------------")
Console.WriteLine("")
Console.WriteLine("")
Console.WriteLine("Press any key to end application...")
Console.ReadLine()
End
End If
' ---
' end of async processes -> display success message
' ---
Console.WriteLine("CDOCS Application update completed successfully... Please press any key to launch the CDOCS application...")
Console.ReadLine()
End SubGreg-DB
Dropbox Community Moderator
6 years agoI just tried running a stripped down version of this code in the same environment (using v5.0.0 of the Dropbox .NET SDK, in a project using VB.NET and .NET Framework 4.6.1 in Visual Studio 2019) and it works correctly for me. I'm able to trigger and catch an exception from DownloadAsync for a non-existant path.
Here's the simplified code:
Private Async Sub Test()
Console.WriteLine("Running Test...")
Dim loDropBoxClient As DropboxClient
Dim loDropBoxClientResponse As Object
Dim csDropBoxUserAccessToken = "<ACCESS_TOKEN>"
Try
loDropBoxClient = New DropboxClient(csDropBoxUserAccessToken)
loDropBoxClientResponse = Await loDropBoxClient.Files.DownloadAsync("/nonexistantpath")
Console.WriteLine("Got response:")
Console.WriteLine(loDropBoxClientResponse)
Catch loDropboxException As DropboxException
Console.WriteLine("Got DropboxException:")
Console.WriteLine(loDropboxException)
Catch loException As Exception
Console.WriteLine("Got Exception:")
Console.WriteLine(loException)
End Try
Console.WriteLine("Test complete.")
Console.ReadLine()
End Sub
Could you give that a try and let me know the issue does or doesn't reproduce with that for you?
- snaidamast6 years agoExplorer | Level 3
Hi Greg...
I just tried my code again as you suggested and it is now trapping the error as one would expect.
However, for some reason, when I submitted this issue, the code in question was in fact not working and causing my application simply to terminate. Why, I do not know unless some type of buffer issue was cuasing the problem.
Steve Naidamast
Sr. Software Engineer
About Discuss Dropbox Developer & API
Make connections with other developers
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!