private void ShellTreeView_AfterLabelEdit(object sender, NodeLabelEditEventArgs e) { if (e.Label != null) { if (e.Label.Length > 0) { if (e.Label.IndexOfAny(new char[] { '@', '.', ',', '!' }) == -1) { // Stop editing without canceling the label change. e.Node.EndEdit(false); var fo = new IIFileOperation(this.Handle); fo.RenameItem((e.Node.Tag as IListItemEx)?.ComInterface, e.Label); fo.PerformOperations(); } else { /* Cancel the label edit action, inform the user, and place the node in edit mode again. */ e.CancelEdit = true; MessageBox.Show("Invalid tree node label.\n The invalid characters are: '@','.', ',', '!'", "Node Label Edit"); e.Node.BeginEdit(); } } else { /* Cancel the label edit action, inform the user, and place the node in edit mode again. */ e.CancelEdit = true; MessageBox.Show("Invalid tree node label.\nThe label cannot be blank", "Node Label Edit"); e.Node.BeginEdit(); } } }
public void RenameShellItem(IShellItem item, String newName, Boolean isAddFileExtension, String extension = "") { var handle = this.Handle; var sink = new FOperationProgressSink(this); var fo = new IIFileOperation(sink, handle, false); fo.RenameItem(item, isAddFileExtension ? newName + extension : newName); fo.PerformOperations(); if (fo.GetAnyOperationAborted()) { this._IsCanceledOperation = true; } }