I am writing a quick and dirty application that reads all the files from a given directory. I'm currently using the OpenFileDialog to choose a directory and just culling off the file name that it provides. It seems like there should be a way to just choose directories though, but in a quick browsing of MSDN I didn't find it.
我正在编写一个快速而肮脏的应用程序,它从给定目录中读取所有文件。我目前正在使用OpenFileDialog来选择一个目录,并删除它提供的文件名。似乎应该有一种选择目录的方法,但是在快速浏览MSDN时,我没有找到它。
If you have a way in winforms or more preferably in WPF I'm all ears.
如果你在winforms (winforms)或者WPF (WPF)里有更好的方法,我洗耳恭听。
2 个解决方案
#2
14
using FORMS = System.Windows.Forms;
var dialog = new System.Windows.Forms.FolderBrowserDialog();
FORMS.DialogResult result = dialog.ShowDialog();
if (result == FORMS.DialogResult.OK)
{
MessageBox.Show("Result: " + dialog.SelectedPath);
}
#1
#2
14
using FORMS = System.Windows.Forms;
var dialog = new System.Windows.Forms.FolderBrowserDialog();
FORMS.DialogResult result = dialog.ShowDialog();
if (result == FORMS.DialogResult.OK)
{
MessageBox.Show("Result: " + dialog.SelectedPath);
}