We Want to Hear From You! What Do You Want to See on the Community? Tell us here!

Forum Discussion

Nenciu D.'s avatar
Nenciu D.
New member | Level 1
10 years ago

How to correctly create a task

I'm trying to create folder and then to store the metadata of create folder:

  try
{
FolderMetadata folderMetadata = client.Files.CreateFolderAsync(newFolderPath).Result;
}
catch (Exception e)
{
string m = e.Message;
}

 

And it crashes without any exception. 

This method is working for oneDrive : LiveOperationResult meResult = liveConnectClient.GetAsync("me").Result; //this gets info about the client and is also an awaitable task

 

So what's the best way to create a folder?

This one?

async Task CreateFolder(string folderName)
{
   var response = await dbx.Files.CreateFolderAsync(folderName);
  
}
 
And then to call:
  System.Threading.Tasks.Task taskCreateFolder = Task.Run(() => CreateFolder(cloudPath));
taskCreateFolder.Wait();
 
Thanks
 

3 Replies

Replies have been turned off for this discussion
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    10 years ago

    Your code looks fine. What do you mean by "it crashes without any exception"? That shouldn't be possible. It looks like you're storing the exception message but not reading it (string m = e.Message). 

    I recommend adding a breakpoint there to see what the actual API exception is. For example, it's possible newFolderPath is invalid.

  • Nenciu D.'s avatar
    Nenciu D.
    New member | Level 1
    10 years ago

    Hi Gregory,

    Thanks for all your answers.

    I'm trying to get the result of a task using the following:

    try

    {

     ListFolderResult allItems = dbxClient.Files.EndListFolder(dbxClient.Files.ListFolderAsync(string.Empty, true));

    }

    catch(ApiException<ListFolderContinueError> err)

    {

    string message = err.Message;

    }

    And not getting any error message.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    10 years ago

    So you're saying the code execution doesn't enter the catch block, which should mean the method succeeded? In that case, from your code, it looks like allItems should then be defined containing the information. What do you do with allItems after this code runs?

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,036 PostsLatest Activity: 7 hours ago
411 Following

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 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!