You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
JayPatel1992
7 years agoHelpful | Level 5
How to check folder exist or not and how to upload image using URL using C#
Hello there, I am using Dropbox.Api. I want to check if folder exist or not. I tired using try and catch block but I think there should be a better way for doing this. Here is my try catch block: ...
- 7 years ago
Didn't get much about SvaeUrlAsync but I used this and it worked perfectly.
List<Images> fiveElements = Images.GetRange(0, 5); foreach (var image in fiveElements) { WebClient webclient = new WebClient(); var stream = new MemoryStream(webclient.DownloadData(image.ImageURL)); var fileName = "Test1.jpg"; var response = await client.Files.UploadAsync(path + "/" + fileName, WriteMode.Overwrite.Instance, true, body: stream); }
And for try catch I used your code but not working well as it throws me out of this method and goes to catch(Exception e) of parent method.
try { await client.Files.GetMetadataAsync(path); } catch (ApiException<Dropbox.Api.Files.GetMetadataError> e) { if (e.ErrorResponse.IsPath && e.ErrorResponse.AsPath.Value.IsNotFound) { Console.WriteLine("Nothing found at path."); } else { // different issue; handle as desired Console.WriteLine(e); } }
Please let me know where I am going wrong.
Thank you. - 7 years ago
Thank you so much for the help. Using await and removing result worked for me.
try { await client.Files.GetMetadataAsync(path); } catch (ApiException<Dropbox.Api.Files.GetMetadataError> e) { if (e.ErrorResponse.IsPath && e.ErrorResponse.AsPath.Value.IsNotFound) { Console.WriteLine("Nothing found at path."); } else { // different issue; handle as desired Console.WriteLine(e); } }
Greg-DB
Dropbox Staff
I don't have a sample available for that unfortunately. The basic idea is to call SaveUrlAsync with the 'path' for where you want to save the file, and the 'url' for the hosted file data to save. Then, if the SaveUrlResult gives you an AsyncJobId, call SaveUrlCheckJobStatusAsync ocasionally to check on the job status.
Please give that a try and let me know if something isn't working as expected.
And yes, using the try/catch pattern is a good way to do that existence check.
JayPatel1992
7 years agoHelpful | Level 5
Didn't get much about SvaeUrlAsync but I used this and it worked perfectly.
List<Images> fiveElements = Images.GetRange(0, 5); foreach (var image in fiveElements) { WebClient webclient = new WebClient(); var stream = new MemoryStream(webclient.DownloadData(image.ImageURL)); var fileName = "Test1.jpg"; var response = await client.Files.UploadAsync(path + "/" + fileName, WriteMode.Overwrite.Instance, true, body: stream); }
And for try catch I used your code but not working well as it throws me out of this method and goes to catch(Exception e) of parent method.
try { await client.Files.GetMetadataAsync(path); } catch (ApiException<Dropbox.Api.Files.GetMetadataError> e) { if (e.ErrorResponse.IsPath && e.ErrorResponse.AsPath.Value.IsNotFound) { Console.WriteLine("Nothing found at path."); } else { // different issue; handle as desired Console.WriteLine(e); } }
Please let me know where I am going wrong.
Thank you.
- Greg-DB7 years agoDropbox StaffI think that's because you're using '.Result' instead of 'await'. That's more of a general C# exception handling matter though, so I can't provide much insight there. You'll probably need to change how you structure your exception handling, or switch to using 'await'.
- JayPatel19927 years agoHelpful | Level 5
Thank you so much for the help. Using await and removing result worked for me.
try { await client.Files.GetMetadataAsync(path); } catch (ApiException<Dropbox.Api.Files.GetMetadataError> e) { if (e.ErrorResponse.IsPath && e.ErrorResponse.AsPath.Value.IsNotFound) { Console.WriteLine("Nothing found at path."); } else { // different issue; handle as desired Console.WriteLine(e); } }
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,911 PostsLatest Activity: 7 hours agoIf 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 or Facebook.
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!