0

I am in a Highschool club where we create windows store apps. I am in charge of the code that allows the user to either download files from their online onedrive storage, or upload files. So far I have successfully logged the user in and gained access to onedrive and display the users name with the following code:

 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();
            }

        }

I gained the code from the following MSDN tutorial: http://msdn.microsoft.com/en-us/library/dn631823.aspx

However when I try to follow the next step, downloading and uploading files, I cannot get it to work. Right now I am just trying to press a button, and have the code download a test file:

  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.
            }
        }

However this code throws the following errors: Error Here

This is straight from the MSDN tutorial, and can't figure out how to fix the error. My best guess is I'm missing a "using" statement, but can't figure out what I am missing. Thanks for any and all help!

Tyler Jones
  • 424
  • 2
  • 10
  • 24
  • Is the path you are using - "skydrive/documents/enter_path" - the friendly path to the document you are looking to download? E.g. are your trying to download a file named "enter_path" in the documents folder? – Jeanine M S Apr 30 '14 at 21:49
  • @JeanineMS No, I am replacing it with the actual file path, "skydrive/documents/textTest.txt" With the errors I was getting I didn't consider the path to be the problem. – Tyler Jones May 01 '14 at 00:11
  • You're declaring your connectClient variable in LoadProfile and it's not accessible from the download button click event. This is what's causing error #2. For error #1, which version of the SDK are you using? – ginach May 01 '14 at 00:18
  • @ginach Oh, that makes sense for error 2! I'm just learning how do this, would the best solution make the connect Client global somehow, or to instantiate another connect Client in the event? For my live SDK I am using 5.5.0.0, I noticed a new version came out, should I upgrade to 5.6? – Tyler Jones May 01 '14 at 00:29
  • 2
    Yes, upgrading should address your other issue. The documentation you're referencing is for the 5.6 version and there were some method and object changes since 5.5. – ginach May 01 '14 at 00:59

1 Answers1

2

Make sure you're updated to use the Live SDK 5.6 binary. Be sure to let us know if you have any other problems with OneDrive integration!

Ryan Gregg
  • 2,015
  • 13
  • 16
  • Hi @RGregg, would you happen to know if it's possible to download form and upload text files to my OneDrive account from a WinForms desktop app in C#? – jay_t55 Jun 13 '14 at 18:20
  • Aeron, this is definitely possible. Inside the Live SDK for Windows is an SDK labeled "desktop" which you can call from C# WinForms. – Ryan Gregg Jun 13 '14 at 20:54
  • @RGregg is it possible to download all files present inside a particular folder on onedrive using foreach to loop through unknown files thats present inside folder and save it using their assigned name to local storage of Windows store app? – Jerin Aug 05 '14 at 06:29
  • @Jerin, that should be possible. It's just a matter of enumerating the files and downloading them to some where in the app's local storage. – Ryan Gregg Aug 12 '14 at 17:52