/// <summary> /// Moves a folder or a file to the specified path. /// </summary> /// <param name="item">A file or a folder.</param> /// <param name="path">Destination path.</param> /// <returns></returns> public static bool MoveDirectoryItem(DirectoryItem item, string path) { if (item.FullPath == path) { return(true); } switch (item.Type) { case DirectoryItemType.File: File.Move(item.FullPath, $"{path}\\{item.Name}"); break; case DirectoryItemType.Folder: try { Directory.Move(item.FullPath, path); } catch { return(false); } break; } return(true); }
private void Grid_MouseDown(object sender, MouseButtonEventArgs e) { var grid = (Grid)sender; var dataView = grid.DataContext as DirectoryItemViewModel; var data = new DirectoryItem { FullPath = dataView.FullPath, Type = dataView.Type }; var obj = new DataObject(data); DragDrop.DoDragDrop(grid, obj, DragDropEffects.Copy); }
/// <summary> /// Sets the active directory to the directory provided. /// </summary> /// <param name="directoryPath">The address of the directory.</param> public void SetDirectory(string directoryPath) { try { ActiveDirectoryCollection = DirectoryItem.GetSubDirectory(directoryPath); ActiveDirectoryName = directoryPath; RaisePropertyChanged("ActiveDirectoryCollection"); } catch (UnauthorizedAccessException) { MessageBoxResult result = MessageBox.Show("Error: Unauthorised Access.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private Task Refresh(DataView directoryListView) { return(ShowOrRefreshAsync(directoryListView, (CancellationToken ct) => DirectoryItem.GetDirectoryItemsAsync <T>(CurrentDirectory, ct))); }
private void Row_DoubleClick(object sender, MouseButtonEventArgs e) { DirectoryItem row = (sender as DataGridRow).Item as DirectoryItem; }