Question

I'm programming an app that interact with dropbox by use DropNet API. I want to check if the folder is exist or not on dropbox in order to I will create one and upload file on it after that. Everything seen fine but if my folder is exist it throw exception. Like this:

if (isAccessToken)
{
    byte[] bytes = File.ReadAllBytes(fileName);
    try
    {
        string dropboxFolder = "/Public/DropboxManagement/Logs" + folder;

        // I want to check if the dropboxFolder is exist here

        _client.CreateFolder(dropboxFolder); 

        var upload = _client.UploadFile(dropboxFolder, fileName, bytes);
    }
    catch (DropNet.Exceptions.DropboxException ex) {
        MessageBox.Show(ex.Response.Content);
    }
}
Was it helpful?

Solution

I'm not familiar with dropnet, but looking at the source code, it appears you should be able to do this by using the GetMetaData() method off of your _client object. This method returns a MetaData object.

Example:

//gets contents at requested path
var metaData = _client.GetMetaData("/Public/DropboxManagement/Logs");
//without knowing how this API works, Path may be a full path and therefore need to check for "/Public/DropboxManagement/Logs" + folder
if (metaData.Contents.Any(c => c.Is_Dir && c.Path == folder)
{
     //folder exists
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top