我正在尝试将FolderBrowserDialog控件中的选定文件夹设置为变量,因此我可以在其他方法中使用它
我到目前为止的代码是:
private void button18_Click(object sender, EventArgs e)
{
DialogResult result = folderBrowserDialog1.ShowDialog();
if (result == DialogResult.OK)
{
//
// The user selected a folder and pressed the OK button.
// We print the number of files found.
//
string[] files = Directory.GetFiles(folderBrowserDialog1.SelectedPath);
MessageBox.Show("Files found: " + files.Length.ToString(), "Message");
}
}
所以我可以通过以下方法调用上面控件中的选定文件夹:
Process.Start("test.exe", <Folder Selection Here> );
答案 0 :(得分:1)
在我注意到您已要求关闭问题之前,我开始查看此内容。无论如何,这里的代码应该对其他人有用。
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
//Choose the default start up folder
string selectedFolder = @"C:\Dev";
//Set that into the dialog
folderBrowserDialog1.SelectedPath = selectedFolder;
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
//Grab the folder that was chosen
selectedFolder = folderBrowserDialog1.SelectedPath;
// The user selected a folder and pressed the OK button.
// We print the number of files found.
string[] files = Directory.GetFiles(selectedFolder);
MessageBox.Show("Files found: " + files.Length.ToString(), "Message");
MessageBox.Show(selectedFolder);
}
}