WP8 - SkyDrive API。检查文件夹是否存在?

时间:2013-12-26 07:50:45

标签: api windows-phone-8 onedrive

有什么方法可以检查“me / SkyDrive”位置的用户SkyDrive帐户中是否存在文件夹?

基本上我只是想知道如何做到这一点,因为我的应用程序具有skydrive功能,如果用户想要“me / Skydrive”中的文件夹,用户可以上传文件。但是每次用户登录SkyDrive帐户时我都添加了创建文件夹。这导致上传功能因为每个团队创建一个文件夹而中断,它会生成一个新的文件夹ID,在上传时会出错。

但重点是有没有办法检查SkyDrive目录中是否存在具有确切名称的文件夹?如果是这样的话?

这是我的代码,它基本上只是记录用户并创建一个文件夹:

private async void btnSignin_SessionChanged(object sender, LiveConnectSessionChangedEventArgs e)
{
    IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
    if (e.Status == LiveConnectSessionStatus.Connected)
    {                      
            session = e.Session;
            client = new LiveConnectClient(session);
            StatusforSKD.Text = "You have signed in.";
            try
            {
                var folderData = new Dictionary<string, object>();
                folderData.Add("name", "File List");
                LiveConnectClient liveClient = new LiveConnectClient(this.session);
                LiveOperationResult operationResult = await liveClient.PostAsync("me/skydrive", folderData);
                dynamic result = operationResult.Result;
                InfoDD.Text = result.id;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "", MessageBoxButton.OK);
            }
    }
    else
    {
        StatusforSKD.Text = "Not signed in.";
        client = null;
    }
}

3 个答案:

答案 0 :(得分:1)

我不确定这个

  • 创建递归,异步函数,调用并等待'Get' LiveConnectClient上的函数,附带?filter =文件夹 查询位置。对于返回的每个项目,检查它的名称 匹配返回true,否则如果没有匹配则再次调用函数 返回假。

此链接不包含代码。只是信息 http://social.msdn.microsoft.com/Forums/windowsapps/en-US/78b0a9b4-bd1b-452f-95fb-5b3acfa6866c/checking-folder-existence-in-skydrive-with-livesdk?forum=messengerconnect

答案 1 :(得分:1)

当您发现异常时,您可以执行以下操作:

if (exception.Message.Contains("already exists")
{
 // ignore error and carry one because the folder already exists
}

答案 2 :(得分:0)

    private async Task GetSkyDriveFolder()
    {
        if (liveClient == null)
            await SignIn();

        //the session is already established, so let's find our folder by its name
        LiveOperationResult result = await liveClient.GetAsync("me/skydrive/files/");
        List<object> data = (List<object>)result.Result["data"];
        foreach (IDictionary<string, object> content in data)
        {
            if (content["name"].ToString() == folderName)
            {
                //The folder has been found!
                folderID = content["id"].ToString();
                MessageBox.Show("Folder exists hurray");

            }
        }


    }

这将检查skydrive中是否存在文件夹