示例#1
0
        /// <summary>
        /// Downloads the file Test.txt from the OneDrive root and displays its contents in the output box
        /// </summary>
        private async void DownloadButton_Click(object sender, EventArgs e)
        {
            // Retrieve the items in the root of the OneDrive
            var items = await OneDriveApi.GetDriveRootChildren();

            // Ensure there are items in the root of this OneDrive
            if (items.Collection.Length == 0)
            {
                JsonResultTextBox.Text = "OneDrive is empty, nothing to download";
                return;
            }

            // Find the first file of which its filename ends with .txt
            var firstTextFileItem = items.Collection.FirstOrDefault(i => i.Name.EndsWith(".txt"));

            if (firstTextFileItem == null)
            {
                JsonResultTextBox.Text = "No .txt file found in the root of this OneDrive to download";
                return;
            }

            // Download the .txt file and render its contents in the output window
            using (var stream = await OneDriveApi.DownloadItem(firstTextFileItem))
            {
                using (var writer = new StreamReader(stream))
                {
                    JsonResultTextBox.Text = await writer.ReadToEndAsync();
                }
            }
        }
示例#2
0
        /// <summary>
        /// Downloads the file Test.txt from the OneDrive root and displays its contents in the output box
        /// </summary>
        private async void DownloadButton_Click(object sender, EventArgs e)
        {
            var item = await OneDriveApi.GetItem("Test.txt");

            if (item != null)
            {
                using (var stream = await OneDriveApi.DownloadItem(item))
                {
                    using (var writer = new StreamReader(stream))
                    {
                        JsonResultTextBox.Text = await writer.ReadToEndAsync();
                    }
                }
            }
            else
            {
                JsonResultTextBox.Text = "Unable to find Test.txt in the OneDrive root";
            }
        }
示例#3
0
        private async void DownloadButton_Click(object sender, EventArgs e)
        {
            var item = await OneDriveApi.GetItem("Test.txt");

            if (item != null)
            {
                var localFolder = new FileInfo(Application.ExecutablePath).DirectoryName;
                var success     = await OneDriveApi.DownloadItem(item, localFolder);

                MessageBox.Show(success ? "Download successful" : "Download failed", "Download", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }