-2

How can I promptly open application's folder using OpenFileDialog ?

        OpenFileDialog openFileDialog1 = new OpenFileDialog();
        openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
        if (openFileDialog1.ShowDialog() == DialogResult.OK)
        {
           ...........

        }
user1872295
  • 15
  • 1
  • 3

2 Answers2

6

Guessing that you mean "Show the OpenFileDialog starting in my application's folder", just set the OpenFileDialog.InitialDir to your application's folder before showing the OpenFileDialog.

string AppPath = Path.GetDirectoryName(Application.ExecutablePath);;
openFileDialog1.InitialDir = AppPath;

If you need help finding your application's directory, see Getting root folder of application

Community
  • 1
  • 1
Ken White
  • 123,280
  • 14
  • 225
  • 444
2

Use the FileDialog.InitialDirectory Property if you wish to override one of the default ways for its value getting set (described on MSDN).

openFileDialog1.InitialDirectory = @"C:\";  // based on comment of question
Austin Salonen
  • 49,173
  • 15
  • 109
  • 139