文件夹:
安装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;
}

本文介绍如何使用C#实现文件与文件夹的选择功能。通过调用Windows API Code Pack提供的CommonOpenFileDialog和OpenFileDialog类,分别实现文件夹与文件的选择对话框,并展示具体的使用代码。

1776

被折叠的 条评论
为什么被折叠?



