是否可以在C#中使用“..//..//FolderName”设置FolderBrowserDialog.SelectedPath?

时间:2014-02-10 09:56:04

标签: c# folderbrowserdialog

FolderBrowserDialog openfolderdialog1 = new FolderBrowserDialog();
openfolderdialog1.SelectedPath = "..\\..\\Gambar Train\\";
if (openfolderdialog1.ShowDialog() == DialogResult.OK)
{
    textBox1.Text = openfolderdialog1.SelectedPath;
}

它不起作用。你有解决方案吗? 我想使用“.. \ ..”因为文件夹位置不固定。

3 个答案:

答案 0 :(得分:1)

在调用ShowDialog ...

之前设置SelectedPath属性
folderBrowserDialog1.SelectedPath = @"c:\temp\";
folderBrowserDialog1.ShowDialog();

将在C:\ Temp

启动它们

SelectedPath Property

答案 1 :(得分:0)

SelectedPath属性为string,而不是DirectoryInfo

尝试

openfolderdialog1.SelectedPath = "..\\..\\Gambar Train\\";

答案 2 :(得分:0)

因为.. \是一个'相对'路径,你需要定义它的相对位置。

所以“.. \ .. \ folder \”将起作用(你的例子不是因为SelectedPath是一个字符串),但你不能说100%该位置的位置。

我会查看Directory.GetCurrentDirectoryAppDomain.CurrentDomain.BaseDirectory之类的内容,并以此为基础确定您的位置。