using System.IO; using System.Windows.Forms; namespace DCIT.App.Presentation { internal static class ModernFolderPicker { public static bool TrySelectFolder(IWin32Window owner, string initialDirectory, out string selectedPath) { selectedPath = null; using (var dialog = new OpenFileDialog()) { dialog.ValidateNames = false; dialog.CheckFileExists = false; dialog.CheckPathExists = true; dialog.FileName = "选择当前文件夹"; dialog.Filter = "文件夹|*.folder"; if (!string.IsNullOrWhiteSpace(initialDirectory) && Directory.Exists(initialDirectory)) { dialog.InitialDirectory = initialDirectory; } if (dialog.ShowDialog(owner) != DialogResult.OK) { return false; } selectedPath = Path.GetDirectoryName(dialog.FileName); return !string.IsNullOrWhiteSpace(selectedPath); } } } }