Reputation: 13509
Which directory does FileDialog (OpenFileDialog/SaveFileDialog) uses?
When I show it from my application it opens folder which is not Environment.CurrentDirectory folder.
How can I get this directory path? Or it's controlled by the OS and I can't know it?
Upvotes: 1
Views: 696
Reputation: 49978
You could make a extern call to GetOpenFileName function to see what the initial OPENFILENAME structure stores (looking at the lpstrInitialDir).
From MSDN: lpstrInitialDir
Pointer to a NULL terminated string that can specify the initial directory.
You could also check the following registry key: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\LastVisitedMRU\
There is a string value named MRUList with an order of indexes named to the binary value. If you open the binary value of the first index (whichever letter it is) in the MRUList you will see the name of your application and the directory.
EDIT: You might find the code at the bottom of this discussion useful if you are trying to set/get it manually.
Upvotes: 0
Reputation: 5186
How about looking at the source code to the method that shows it, and see what string it uses?
Upvotes: 0
Reputation: 292435
This information is stored in the registry on a per-application basis, so you should be able to retrieve it. I don't remember the exact registry location, I'll try to find it...
EDIT:
On Windows7, it is stored in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\LastVisitedPidlMRU
The value names are just numbers, and the content is encoded in some binary format, so it's probably not very easy to read...
Upvotes: 1
Reputation: 68687
According to 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.
Otherwise it doesn't seem to say anything, for me it looked like the Environment.SpecialFolder.MyDocuments, I'm using Vista.
Upvotes: 2