private async void AllView_CellEditEnded(object sender, DataGridCellEditEndedEventArgs e) { //var NewCellText = (e.Column.GetCellContent(e.Row) as TextBlock).Text.ToString(); var NewCellText = (GenericFileBrowser.data.SelectedItem as ListedItem).FileName; var SelectedItem = ItemViewModel.FilesAndFolders[e.Row.GetIndex()]; if (SelectedItem.FileExtension == "Folder") { StorageFolder FolderToRename = await StorageFolder.GetFolderFromPathAsync(SelectedItem.FilePath); if (FolderToRename.Name != NewCellText) { await FolderToRename.RenameAsync(NewCellText); } } else { StorageFile FileToRename = await StorageFile.GetFileFromPathAsync(SelectedItem.FilePath); if (FileToRename.Name != NewCellText) { await FileToRename.RenameAsync(NewCellText); } } }
/// <summary> /// Renames the folder. /// Any existing folder at the destination will be replaced. /// </summary> /// <param name="storageFolder">The <see cref="StorageFolder"/>.</param> /// <param name="newName">The new name of the folder.</param> /// <param name="cancellationToken"> /// A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation. /// </param> /// <returns> /// A <see cref="StorageFolder"/> instance representing the renamed folder. /// </returns> /// <remarks> /// Calling this method is equivalent to calling /// <see cref="StorageFolder.RenameAsync(string, NameCollisionOption, CancellationToken)"/> /// with the <see cref="NameCollisionOption.ReplaceExisting"/> parameter. /// </remarks> /// <exception cref="ArgumentNullException"> /// <paramref name="storageFolder"/> or <paramref name="newName"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="newName"/> is empty or contains one or more invalid characters. /// Invalid characters are: /// /// <list type="bullet"> /// <item> /// <description>The directory separator character</description> /// </item> /// <item> /// <description>The alternative directory separator character</description> /// </item> /// <item> /// <description>The volume separator character</description> /// </item> /// </list> /// /// You can use the <see cref="FileSystem.PathInformation"/> property of this folder's /// <see cref="StorageElement.FileSystem"/> property to determine which characters are allowed. /// </exception> /// <exception cref="OperationCanceledException"> /// The operation was cancelled via the specified <paramref name="cancellationToken"/>. /// </exception> /// <exception cref="UnauthorizedAccessException"> /// Access to the folder is restricted. /// </exception> /// <exception cref="PathTooLongException"> /// The length of the folder's path exceeds the system-defined maximum length. /// </exception> /// <exception cref="IOException"> /// The folder does not exist. /// /// -or- /// /// A conflicting file exists at the destination. /// /// -or- /// /// An I/O error occured while interacting with the file system. /// </exception> /// <exception cref="DirectoryNotFoundException"> /// One of the folder's parent folders does not exist. /// </exception> public static Task <StorageFolder> RenameOrReplaceExistingAsync( this StorageFolder storageFolder, string newName, CancellationToken cancellationToken = default ) { _ = storageFolder ?? throw new ArgumentNullException(nameof(storageFolder)); return(storageFolder.RenameAsync(newName, NameCollisionOption.ReplaceExisting, cancellationToken)); }
private async void AllView_CellEditEnded(object sender, DataGridCellEditEndedEventArgs e) { var newCellText = (data.SelectedItem as ListedItem)?.FileName; var selectedItem = instanceViewModel.FilesAndFolders[e.Row.GetIndex()]; if (selectedItem.FileType == "Folder") { StorageFolder FolderToRename = await StorageFolder.GetFolderFromPathAsync(selectedItem.FilePath); if (FolderToRename.Name != newCellText) { await FolderToRename.RenameAsync(newCellText); AllView.CommitEdit(); } else { AllView.CancelEdit(); } } else { StorageFile fileToRename = await StorageFile.GetFileFromPathAsync(selectedItem.FilePath); if (fileToRename.Name != newCellText) { await fileToRename.RenameAsync(newCellText); AllView.CommitEdit(); } else { AllView.CancelEdit(); } } //Navigation.NavigationActions.Refresh_Click(null, null); }