OpenFileDialog Initial Directory not working

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Greg

    OpenFileDialog Initial Directory not working

    I'm a bit confused by this - when I set the InitialDiretory of an
    OpenFileDialog to be a subfolder within the same folder as the app, the
    file dialog does not initially display the folder - instead it shows
    the last used folder (this persists after closing the app).

    However, if I use a different path (e.g. "C:\\") then every time the
    dialog is shown, it starts at the correct directory every time.

    Is there something special about an app path that a file dialog doesn't
    like, or is my syntax wrong???

    OpenFileDialog objOpenDlg = new OpenFileDialog( );
    objOpenDlg.Init ialDirectory = Application.Exe cutablePath + @"\Games\";
    if (objOpenDlg.Sho wDialog() == DialogResult.OK )
    {
    //do some stuff here
    }

    It doesn't seem to make any difference whether the app is a debug or
    release mode, and whether it is run from the IDE or not.

    Any thoughts???

    Greg.

  • Truong Hong Thi

    #2
    Re: OpenFileDialog Initial Directory not working

    Hi Greg,

    Use Application.Sta rtupPath instead. Application.Exe cutablePath
    includes the file name.

    objOpenDlg.Init ialDirectory = Path.Combine(Ap plication.Start upPath,
    "Games");

    Regards,
    Thi

    Comment

    • Greg

      #3
      Re: OpenFileDialog Initial Directory not working

      Excellent, thanks a lot!

      Comment

      Working...