0
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.

go eng chun
  • 73
  • 2
  • 10

3 Answers3

1

Set the SelectedPath property before you call ShowDialog ...

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

Will start them at C:\Temp

SelectedPath Property

Community
  • 1
  • 1
Vignesh Kumar A
  • 27,863
  • 13
  • 63
  • 115
0

The SelectedPath property is a string, not a DirectoryInfo.

Try

openfolderdialog1.SelectedPath = "..\\..\\Gambar Train\\";
John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • i forgot to edit the question. I already changed it to string, the problem is my folder is relative (..\\..\\) not (C:\\test\\) – go eng chun Feb 10 '14 at 10:14
0

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.

cjb110
  • 1,310
  • 14
  • 30
  • do you know how to give focus at selected path ? cause the dialog show up but the focus still in root folder – go eng chun Feb 10 '14 at 10:24
  • If your setting the `SelectedPath` but the dialog isn't at that path, my first thought would be it doesn't exist, or you don't have access. – cjb110 Feb 10 '14 at 10:39
  • it's already there but my view is still at the top or the rootfolder. – go eng chun Feb 10 '14 at 11:37