private void RenameLocalFolder() { if (GridViewLocalFiles.SelectedRowsCount > 0) { string oldFolderName = GridViewLocalFiles.GetRowCellValue(GridViewLocalFiles.FocusedRowHandle, "Name").ToString(); string oldFolderPath = TextBoxLocalPath.Text + @"\" + oldFolderName; string newFolderName = StringExtensions.ReplaceInvalidChars(DialogExtensions.ShowTextInputDialog(this, "Rename Folder", "Folder Name:", oldFolderName)); string newFolderPath = TextBoxLocalPath.Text + @"\" + newFolderName; if (newFolderName != null && !newFolderName.Equals(oldFolderName)) { if (!Directory.Exists(newFolderPath)) { SetLocalStatus("A folder with this name already exists."); } else { SetLocalStatus($"Renaming folder to: {newFolderName}"); FileSystem.RenameDirectory(oldFolderPath, newFolderName); SetLocalStatus($"Successfully renamed folder to: {newFolderName}"); LoadLocalDirectory(DirectoryPathLocal); } } } }
public static string ShowTextInputDialog(Form owner, string title, string labelText, string inputText) { using (var inputDialog = new InputDialog { Text = title }) { inputDialog.LabelName.Text = labelText; inputDialog.TextBoxName.Text = inputText; return(inputDialog.ShowDialog(owner) == DialogResult.OK ? StringExtensions.ReplaceInvalidChars(inputDialog.TextBoxName.Text.Trim()) : null); } }