我的C#代码目前遇到了一个奇怪的问题.我试图使用folderBrowserDialog来检索用户选择的文件夹的路径.
一旦用户单击按钮确认选择(所选路径显示在"textBox1"中),如果找到文件夹位置,则应返回消息"建立连接"(如果找到目录/文件)或"无连接"发现"(如果文件/目录不存在).
然而,由于一些奇怪的原因,在检查目录是否存在时,代码似乎总是返回false - 是的,它确实存在.我的应用程序在它的清单文件中请求管理员权限,因为我认为这可以解决问题,所以我仍然难以接受这个问题.
private void button1_Click(object sender, EventArgs e)
{
//BROWSE
folderBrowserDialog1.ShowDialog();
textBox1.Text = folderBrowserDialog1.SelectedPath;
}
private void button2_Click(object sender, EventArgs e)
{
var path = textBox1.Text + @"\" + "connection.pss";
//ESTABLISH CONNECTION
if (textBox1.TextLength > 0)
{
if (Directory.Exists(path))
{
connectionstatus.Text = "CONNECTION ESTABLISHED!";
//SET UP VARIABLES
}
if (!Directory.Exists(path))
{
connectionstatus.Text = "NO CONNECTION FOUND!";
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3392 次 |
| 最近记录: |