简体   繁体   English

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

[英]How to check a folder exists in DropBox using DropNet

I'm programming an app that interact with dropbox by use DropNet API. 我正在编写一个使用DropNet API与Dropbox交互的应用程序。 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);
    }
}

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. 我对Dropnet并不熟悉,但是看一下源代码,看来您应该能够通过使用_client对象之外的_client GetMetaData()方法来做到这一点。 This method returns a MetaData object. 此方法返回一个MetaData对象。

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM