Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenFileDialog InitialDirectory doesn't work

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?

like image 434
Mircea Ispas Avatar asked Jan 11 '12 10:01

Mircea Ispas


2 Answers

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.

like image 180
Sergey Avatar answered Sep 21 '22 06:09

Sergey


to me those answers didn't help (windows 7).

my path looked like this: "C:/xxxx/yyyyy" after switching to backslash it worked fine, my path now looks like this: "C:\xxxxx\yyyyy"

like image 25
Veit Avatar answered Sep 24 '22 06:09

Veit