OpenFileDialog InitialDirectory doesn't work

Mircea Ispas picture Mircea Ispas · Jan 11, 2012 · Viewed 17.6k times · Source

I have this code:

OpenFileDialog dialog = new OpenFileDialog();
dialog.InitialDirectory = GetDataPath(...);
dialog.AutoUpgradeEnabled = false;
dialog.Filter = GetFilter(...);
if (dialog.ShowDialog(this) == DialogResult.OK)
{...}

I expect, at every run, to have the dialog in same folder - GetDataPath(...) folder, but it remains in the last selected folder.

Is this the correct behavior? Do you know how to fix this? If Windows saves last used path in registry do you know how to find it?

EDIT1:

With:

dialog.AutoUpgradeEnabled = true;

is working as expected...

EDIT2: same problem as here Any known problems with getting SaveFileDialog's InitialDirectory property working in Windows 7?

Answer

Sergey picture Sergey · Jan 13, 2014

Do no include filename to InitialDirectory. Path only.

From msdn: On Windows Vista, if InitialDirectory is set to a full file name instead of just a directory path, the initial directory will default either to the application path, or to the directory from which the user last selected a file.