2

According to this msdn article one of the sources for InitialDirectory property used in FileDialog is:

A path that was previously used in the program, perhaps retained from the last directory or file operation.

...

So if you selected your first file from folder x, the next time you try to select a file it will open up the FileDialog with with folder x selected (saving you having to navigate there).

Playing around with notepad this seems to carry across opening a file, saving a file, opening a file and even when printing with "Microsoft XPS Document Writer" which brings up it's own dialog.

So my question is where is this value stored between dialogs? I would like to be able to see what it is and potentially change it? The specific area i would like to change it is in the "Microsoft XPS Document Writer" printer which brings up it's own dialog. So it's not as simple as just setting the initalDirectory Value.

Community
  • 1
  • 1
AidanO
  • 868
  • 1
  • 11
  • 33

2 Answers2

1

It's stored in the registry, somewhere in HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\ (LastVisitedPidlMRU).

ken2k
  • 48,145
  • 10
  • 116
  • 176
0

You should take a look at this link: MRU locations are what you are looking at!

Here's a way for accessing it:

var openFileDialog1 = new OpenFileDialog();
string path = openFileDialog1.InitialDirectory;
// you can change path if you want
openFileDialog1.InitialDirectory = path;
// after you are donw you can display you dialog
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
      // do something
}

Another way is to use Directory.SetCurrentDirectory method which sets the application's current working directory

And from Microsoft website, it is stored at this location in the registry:

//The MRU lists for Windows Explorer-style dialog boxes are stored by file type for each user in the following registry key:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\OpenSaveMRU

hope this helps

TrizZz
  • 1,200
  • 5
  • 15
  • 1
    should: string path = openFileDialog1.InitialDirectory = initialDirectory; be string path = openFileDialog1.InitialDirectory; ?? – AidanO Aug 20 '12 at 12:39
  • True!, thx for this highlight! had a copy paste error from my code :) it's fixed now – TrizZz Aug 20 '12 at 12:41