Пример #1
0
        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);
                }
            }
        }
Пример #2
0
 /// <summary>
 ///     Renames the file.
 ///     Any existing file at the destination will be replaced.
 /// </summary>
 /// <param name="storageFile">The <see cref="StorageFile"/>.</param>
 /// <param name="newName">The new name of the file.</param>
 /// <param name="cancellationToken">
 ///     A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.
 /// </param>
 /// <returns>
 ///     A <see cref="StorageFile"/> instance representing the renamed file.
 /// </returns>
 /// <remarks>
 ///     Calling this method is equivalent to calling
 ///     <see cref="StorageFile.RenameAsync(string, NameCollisionOption, CancellationToken)"/>
 ///     with the <see cref="NameCollisionOption.ReplaceExisting"/> parameter.
 /// </remarks>
 /// <exception cref="ArgumentNullException">
 ///     <paramref name="storageFile"/> 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 file'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 file is restricted.
 /// </exception>
 /// <exception cref="PathTooLongException">
 ///     The length of the file's path exceeds the system-defined maximum length.
 /// </exception>
 /// <exception cref="IOException">
 ///     A conflicting folder exists at the destination.
 ///
 ///     -or-
 ///
 ///     An I/O error occured while interacting with the file system.
 /// </exception>
 /// <exception cref="DirectoryNotFoundException">
 ///     One of the file's parent folders does not exist.
 /// </exception>
 /// <exception cref="FileNotFoundException">
 ///     The file does not exist.
 /// </exception>
 public static Task <StorageFile> RenameOrReplaceExistingAsync(
     this StorageFile storageFile,
     string newName,
     CancellationToken cancellationToken = default
     )
 {
     _ = storageFile ?? throw new ArgumentNullException(nameof(storageFile));
     return(storageFile.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);
        }