private async void RenameToolStripMenuItem_Click(object sender, EventArgs e) { if (CloudLocationPicker.SelectedItems.Count == 0) { return; } if (CloudLocationPicker.SelectedItems[0].Tag == null) { return; } var renameItemDialog = new OneDriveRequestInputDialog { FormTitle = "Enter new name", InputValue = CloudLocationPicker.SelectedItems[0].Text }; renameItemDialog.ShowDialog(this); if (renameItemDialog.DialogResult != DialogResult.OK) { return; } try { var oneDriveItemToRename = await _oneDriveApi.GetItemById(CloudLocationPicker.SelectedItems[0].Tag.ToString()); var operationSuccessful = await _oneDriveApi.Rename(oneDriveItemToRename, renameItemDialog.InputValue); if (operationSuccessful) { MessageBox.Show("Item has been renamed", "Rename item", MessageBoxButtons.OK, MessageBoxIcon.Information); await LoadFolderItems(CurrentMyOneDriveItem != null?CurrentMyOneDriveItem.Id : null); } else { MessageBox.Show("Item could not be renamed", "Rename item", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (Exception) { MessageBox.Show("Item could not be renamed", "Rename item", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
/// <summary> /// Renames the file Test.txt in the OneDrive root to 'Renamed Test.txt' /// </summary> private async void RenameButton_Click(object sender, EventArgs e) { var success = await OneDriveApi.Rename("Test.txt", "Renamed Test.txt"); JsonResultTextBox.Text = success ? "Rename Successfull" : "Rename Failed"; }