Is it possible to set FolderBrowserDialog.SelectedPath with "..//..//FolderName" in C#?

StackOverflow https://stackoverflow.com/questions/21673923

  •  09-10-2022
  •  | 
  •  

質問

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

It is not working. Do you have solution for this ? i want to use "..\.." cause the folder location is not fixed.

役に立ちましたか?

解決 2

As ..\ is a 'relative' path, you need to define what its relative to.

So "..\..\folder\" will work (your example isn't because SelectedPath is a string), but you can't say 100% where that location will be.

I would look at things like the Directory.GetCurrentDirectory or AppDomain.CurrentDomain.BaseDirectory and base your location on that.

他のヒント

Set the SelectedPath property before you call ShowDialog ...

folderBrowserDialog1.SelectedPath = @"c:\temp\";
folderBrowserDialog1.ShowDialog();

Will start them at C:\Temp

SelectedPath Property

The SelectedPath property is a string, not a DirectoryInfo.

Try

openfolderdialog1.SelectedPath = "..\\..\\Gambar Train\\";
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top