-2

Currently have no experience in programming and have been chucked in the deep end. I've currently made a simple UWP app that has a text box and a button. I want it so when I type in the text box and hit the button, the content from that text box is stored into a onedrive account as a text file. currently I have thee layout done and I've double clicked the button to enter the cose but I don't know what else to do and I havent had much luck with googling around. Any help or solutions? Thanks!

  • 1
    Very first hit on google: https://msdn.microsoft.com/en-us/magazine/mt614268.aspx – Bart Jul 20 '16 at 10:37

1 Answers1

0

We can use OneDrive API to do this in UWP apps. This is a modern REST API and based on this API there are some OneDrive SDKs for different platforms to quickly start using the OneDrive API without the need to get into all the details of authentication, JSON parsing, HTTP connections and more. As you are using C#, OneDrive SDK for C# is strongly recommended.

For more info about how to use this SDK in UWP apps, please see Getting started and Documentation and resources on GitHub and also the article: Windows 10 - Implementing a UWP App with the Official OneDrive SDK.

Following is a simple sample. In the sample, I used OneDrive's App Folder, this folder is a dedicated, special folder for your app. It is typically named after your app, and is found in the Apps folder in the user's OneDrive. If you request the onedrive.appfolder permission scope and the user authorizes it, your app gets read and write access to this folder.

private async void Button_Click(object sender, RoutedEventArgs e)
{
    var oneDriveClient = await OneDriveClientExtensions.GetAuthenticatedUniversalClient(new[] { "onedrive.appfolder" });

    using (var contentStream = new MemoryStream(Encoding.UTF8.GetBytes(textBox.Text)))
    {
        var item = await oneDriveClient.Drive.Special.AppRoot.ItemWithPath("backup.txt").Content.Request().PutAsync<Item>(contentStream);
    }
}
Jay Zuo
  • 15,653
  • 2
  • 25
  • 49