如何使用DropNet检查DropBox中是否存在文件夹

时间:2013-11-29 02:11:52

标签: c# dropbox dropnet

我正在编写一个使用DropNet API与Dropbox交互的应用程序。我想检查文件夹是否存在于Dropbox上,以便我之后创建一个并上传文件。一切都很好,但如果我的文件夹存在,它会抛出异常。像这样:

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);
    }
}

1 个答案:

答案 0 :(得分:3)

我不熟悉dropnet,但是查看源代码,看来你应该能够使用_client对象的GetMetaData()方法来实现这一点。此方法返回MetaData对象。

示例:

//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
}