如何使用的OpenFileDialog选择文件夹? [英] How to use OpenFileDialog to select a folder?
问题描述
如何使用打开文件对话框
来选择文件夹?
How to use OpenFileDialog
to select folders?
我要使用下列项目:<一href=\"https://github.com/scottwis/OpenFileOrFolderDialog\">https://github.com/scottwis/OpenFileOrFolderDialog
不过,我面临的一个问题。它使用 GetOpenFileName
功能和 OPENFILENAME
结构。和 OPENFILENAME
有一个名为成员 templateID
。它是对话框模板的标识符。而该项目包含 res1.rc
文件和模板对话框初始化了。但我无法弄清楚如何将此文件添加到我的C#项目。
However, I faced one problem. It uses the GetOpenFileName
function and OPENFILENAME
structure. And OPENFILENAME
has the member named templateID
. It's the identifier for dialog template. And the project contains the res1.rc
file and the templated dialog init, too. But I couldn't figure out how to attach this file to my C# project.
有没有用更好的方式了打开文件对话框
来选择文件夹?
Is there a better way to use an OpenFileDialog
to select folders?
推荐答案
基本上你需要在 <一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.folderbrowserdialog.aspx\"><$c$c>FolderBrowserDialog$c$c>类:
提示用户选择一个文件夹。此类不能被继承。
Prompts the user to select a folder. This class cannot be inherited.
例如:
FolderBrowserDialog fbd = new FolderBrowserDialog();
DialogResult result = fbd.ShowDialog();
if (!string.IsNullOrWhiteSpace(fbd.SelectedPath))
{
string[] files = Directory.GetFiles(fbd.SelectedPath);
System.Windows.Forms.MessageBox.Show("Files found: " + files.Length.ToString(), "Message");
}
如果你在工作的 WPF 您必须添加引用 System.Windows.Forms的
。
If you work in WPF you have to add the reference to System.Windows.Forms
.
您还必须添加使用System.IO
为目录
类
这篇关于如何使用的OpenFileDialog选择文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!