如何下载/上传文件到用户的onedrive上

时间:2014-04-30 20:18:32

标签: c# msdn live-connect-sdk onedrive

我在Highschool俱乐部,在那里我们创建了Windows应用商店。我负责允许用户从他们的在线onedrive存储下载文件或上传文件的代码。到目前为止,我已成功登录用户并获得对onedrive的访问权限,并使用以下代码显示用户名:

 private async void LoadProfile()
        {
            bool connected = false;
            string text = "No Error:";

            try
            {
                var authClient = new LiveAuthClient();
                LiveLoginResult result = await authClient.LoginAsync(new List<string>() {"wl.signin", "wl.skydrive"});


                if (result.Status == LiveConnectSessionStatus.Connected)
                {
                    connected = true;
                    var connectClient = new LiveConnectClient(result.Session);
                    var meResult = await connectClient.GetAsync("me");
                    dynamic meData = meResult.Result;
                    Textblock_profilename.Text = meData.name;
                }
            }
            catch (LiveAuthException ex)
            {
                //Set text to corresponding error
                text = ex.ToString();
            }
            catch (LiveConnectException ex)
            {
                //Set text to corresponding error 
                text = ex.ToString();
            }


            if (text[0].ToString() != "N")
            {
                var dialog = new Windows.UI.Popups.MessageDialog(text);
                await dialog.ShowAsync();
            }

        }

我从以下MSDN教程获得了代码:http://msdn.microsoft.com/en-us/library/dn631823.aspx

然而,当我尝试按照下一步,下载和上传文件时,我无法让它工作。现在我只想按一个按钮,让代码下载一个测试文件:

  private async void Button_downloadFile_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                LiveDownloadOperation operation = await connectClient.CreateBackgroundDownloadAsync("skydrive/documents/enter_path");
                var result = await operation.StartAsync();
                //DO SOMETHING WITH RESULT HERE

            }
            catch
            {
                // Handle any errors.
            }
        }

但是,此代码会引发以下错误: Error Here

这是直接来自MSDN教程,无法弄清楚如何修复错误。我最好的猜测是我错过了“使用”声明,但无法弄清楚我错过了什么。感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

确保您已更新为使用Live SDK 5.6二进制文件。如果您在OneDrive集成方面遇到任何其他问题,请务必告诉我们!