【C#】【WPF】【代码记录】打开文件夹选择、打开文件选择

2025-08-27 03:32:16   世界杯足球场

【导图】:

实现效果:

选择文件夹

打开图片文件选择:

打开图片选择:

private string openFileDialog()

{

OpenFileDialog openFileDialog = new OpenFileDialog();

openFileDialog.Filter = "图片|*.jpg;*.png;*.bmp";

openFileDialog.DefaultExt = ".png";

if (openFileDialog.ShowDialog() == true)

{

return openFileDialog.FileName;

}

return string.Empty;

}

打开文件夹选择:

1.下载NuGet包

2.

using Microsoft.WindowsAPICodePack.Dialogs;// 要using

private string openFolderDialog()

{

var dlg = new CommonOpenFileDialog();

dlg.IsFolderPicker = true;

if (dlg.ShowDialog() == CommonFileDialogResult.Ok)

{

var folder = dlg.FileName;

return folder;

}

return string.Empty;

}

《王者荣耀》24日体验服关羽已上架 关羽正式上线时间
“口”的时候,为什么劝你一定要戴套?