文件夹:
安装WindowsAPICodePack-Shell包
using Microsoft.WindowsAPICodePack.Dialogs;
var dlg = new CommonOpenFileDialog();
dlg.IsFolderPicker = true;
if (dlg.ShowDialog() == CommonFileDialogResult.Ok)
{
var folder = dlg.FileName;
}
IsFolderPicker 为FALSE 则是选择文件
文件:
var openFileDialog = new Microsoft.Win32.OpenFileDialog()
{
Filter = "全部文件|*.*",
//Multiselect = true
};
var result = openFileDialog.ShowDialog();
if (result == true)
{
string fileName = openFileDialog.FileName;
}