locked
About LiveConnectClient.GetAsync RRS feed

  • Question

  • During the process of develop live application, I was looking for the online help for getting file or folder on OneDrive. I found a sample code on a web page. But I can't understand the usage for GetAsync method.

    The code is as follow:

    private async void btnReadFolder_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            LiveConnectClient liveClient = new LiveConnectClient(this.session);
            LiveOperationResult operationResult =
                await liveClient.GetAsync("folder.8c8ce076ca27823f.8C8CE076CA27823F!126");
            dynamic result = operationResult.Result;
            infoTextBlock.Text = "Folder name: " + result.name + ", ID: " + result.id;
        }
        catch (LiveConnectException exception)
        {
            infoTextBlock.Text = "Error getting folder info: " + exception.Message;
        }
    }

    It seems that the string "folder.8c8ce076ca27823f.8C8CE076CA27823F!126" is FOLDER_ID. If it is true, how can I get my folder ID on my OneDrive?

    Tuesday, May 5, 2015 6:42 AM

Answers

  • You'll need to request the users folders/files first by providing the path.  In this case, I'm using "me/skydrive/files".  Additional paths can be found at https://msdn.microsoft.com/en-us/library/jj680723.aspx which helps explain how to work through the OneDrive directory.

    private async void btnFriendName_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            LiveAuthClient auth = new LiveAuthClient();
            LiveLoginResult loginResult = await auth.LoginAsync(new string[] { "wl.basic" });
            if (loginResult.Status == LiveConnectSessionStatus.Connected)
            {
                this.infoTextBlock.Text = "Signed in.";
            }
            LiveConnectClient connect = new LiveConnectClient(auth.Session);
            LiveOperationResult operationResult = await connect.GetAsync("me/skydrive/files");
            dynamic resultList = operationResult.Result;
            StringBuilder skyFolders = new StringBuilder();
            foreach (dynamic result in resultList.data)
            {
                skyFolders.Append(result.name);

                skyFolders.Append(result.id);

                skyFolders.Append("\n");
            }
            this.infoTextBlock.Text = skyFolders.ToString();
        }
        catch (LiveAuthException exception)
        {
            this.infoTextBlock.Text = "Error signing in: " + exception.Message;
        }
        catch (LiveConnectException exception)
        {
            this.infoTextBlock.Text = "Error getting files or folders: " + exception.Message;
        }
    }

    • Marked as answer by 缺氧 Wednesday, May 6, 2015 1:53 AM
    Tuesday, May 5, 2015 9:18 PM