go eng chun
go eng chun

Reputation: 73

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

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.

Upvotes: 0

Views: 4872

Answers (3)

cjb110
cjb110

Reputation: 1491

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.

Upvotes: 0

John Saunders
John Saunders

Reputation: 161831

The SelectedPath property is a string, not a DirectoryInfo.

Try

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

Upvotes: 0

Vignesh Kumar A
Vignesh Kumar A

Reputation: 28413

Set the SelectedPath property before you call ShowDialog ...

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

Will start them at C:\Temp

SelectedPath Property

Upvotes: 1

Related Questions