Search code examples
c#folderbrowserdialog

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.


Solution

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