471,317 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,317 software developers and data experts.

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.InitialDirectory = Application.ExecutablePath + @"\Games\";
if (objOpenDlg.ShowDialog() == 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.

Dec 16 '05 #1
2 7654
Hi Greg,

Use Application.StartupPath instead. Application.ExecutablePath
includes the file name.

objOpenDlg.InitialDirectory = Path.Combine(Application.StartupPath,
"Games");

Regards,
Thi

Dec 16 '05 #2
Excellent, thanks a lot!

Dec 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Nagachandra Sekhar Grandhi | last post: by
4 posts views Thread by Eps | last post: by
6 posts views Thread by barbara_dave | last post: by
14 posts views Thread by Ithaqua | last post: by
4 posts views Thread by NickP | last post: by
5 posts views Thread by =?Utf-8?B?UGVy?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.