【问题标题】:How to check a folder exists in DropBox using DropNet如何使用 DropNet 检查 DropBox 中是否存在文件夹
【发布时间】:2013-11-29 02:11:52
【问题描述】:

我正在编写一个使用 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);
    }
}

【问题讨论】:

    标签: c# dropbox dropnet


    【解决方案1】:

    我不熟悉 dropnet,但查看源代码,您似乎可以通过使用 GetMetaData() 对象的 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
    }
    

    【讨论】:

    • 非常感谢您的帮助!我明白了。
    • 顺便说一句,您可能根本不需要创建文件夹。当您在 Dropbox 中写入文件时,会隐式创建文件夹。 (所以如果你写一个文件/Public/DropboxManagement/Logs/hello.txt,必要时会创建文件夹/Public/DropboxManagement/Logs。)
    猜你喜欢
    • 2016-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    • 2011-11-15
    • 1970-01-01
    相关资源
    最近更新 更多