private async Task <OneDriveItem> UploadToOneDriveAsync(DesktopFileSource selectedFile) { bool isConnected = await ConnectToOneDriveAsync(); if (!isConnected) { return(null); } OneDriveItem uploadedItem = null; try { OneDriveItem rootFolder = await ODClient.GetOneDriveRootAsync(); OneDriveItem[] itemsInRootFolder = await rootFolder.GetChildItemsAsync(); uploadedItem = await rootFolder.UploadFileAsync(selectedFile, OverwriteOption.Rename, null, this); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } return(uploadedItem); }
private async void buttonUploadToOneDrive_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxLocalFile.Text)) { MessageBox.Show("Select a file to upload first"); return; } if (!File.Exists(textBoxLocalFile.Text)) { MessageBox.Show("File path is invalid. Select a valid file and try again."); return; } DesktopFileSource selectedFile = new DesktopFileSource(textBoxLocalFile.Text); OneDriveItem uploadedItem = await UploadToOneDriveAsync(selectedFile); if (null != uploadedItem) { textBoxFileIdentifer.Text = uploadedItem.Identifier; MessageBox.Show("Upload complete"); } }