文件夹浏览器对话框对路径的访问无效
本文关键字:访问 无效 路径 浏览器 对话框 文件夹 | 更新日期: 2023-09-27 18:07:31
每次我运行程序,它有一个错误,说访问路径被拒绝。我已经勾选了"允许所有用户"文件夹,勾选了"只读",但仍然不起作用
private void button2_Click(object sender, EventArgs e)
{
try
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
DialogResult result = fbd.ShowDialog();
string[] files = Directory.GetFiles(fbd.SelectedPath);
textBox2.Text = fbd.SelectedPath;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
添加检查结果
DialogResult result = fbd.ShowDialog();
if (result == DialogResult.OK)
{
string[] files = Directory.GetFiles(fbd.SelectedPath);
textBox2.Text = fbd.SelectedPath;
}
检查这个人…
private void button2_Click(object sender, EventArgs e)
{
try
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
DialogResult result = fbd.ShowDialog();
textBox2.Text = (result == DialogResult.OK) ? fbd.SelectedPath : string.Empty;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}