Using OpenFileDialog w/ a relative path as initialDirectory

13,378

use:

openFileDialog.InitialDirectory = Path.Combine(Application.StartupPath,
@"YourSubDirectoryName");

Edit: or try this if you prefer... are you in windows forms?

openFileDialog.InitialDirectory = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), @"YourSubDirectoryName");

Edit 2 for WPF:

string path = System.Reflection.Assembly.GetExecutingAssembly().Location;

... from the Microsoft Forums...

Share:
13,378
Marti
Author by

Marti

Updated on June 05, 2022

Comments

  • Marti
    Marti almost 2 years

    I'd like to give the appropriate value to Initial directory, so it would open the folder (called "Images") which I created in my project. I must use a relative path, so my program works not depending on the computer I work . But the problem is I don't know how to access this folder...

    Does anyone know how to solve this problem?