Files
DCIT/DCIT.App/Presentation/ModernFolderPicker.cs

34 lines
1.1 KiB
C#
Raw Permalink Normal View History

2026-07-13 10:04:36 +08:00
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);
}
}
}
}