Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2005

Tip: Looking for answers? Try searching our database.

Retrieving the real initial directory before a file dialog is opened?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Keith - 08 Aug 2005 17:19 GMT
Hello,

I'm trying to get the "about to be used" directory  from an Open/Save file
dialog.  I'm not talking about InitialDirectory (which only seems to be
useful if you are setting it) but the directory whose contents will be
displayed when the dialog is shown if InitialDirectory is untouched.

For example, if the user previously browsed to directory FOO using the
SaveFileDialog, I'd like to be able to get that directory from the next
instance of the dialog, BEFORE it is shown or any user interaction takes
place.  It is obviously persisted, since it opens there automatically if
InitialDialog is not set, but I can't seem to find the right property or
method to request it.  Do I have to get if from somewhere in the Registry?
Is it a system property?  An environment setting?

// Nonsesical example code
private void SomeFunction()
{
   SaveFileDialog sfd1 = new SaveFileDialog();
   sfd1.ShowDialog();  //  assume the user browsed to directory A and
saved.

   SaveFileDialog sfd2 = new SaveFileDialog();
   //    Here I want to know what the directory used by sfd1 was.
InitialDirectory is "", but sfd2
   //     will open to directory A regardless.  Where is this value stored?
How can I get it?
   sfd2.ShowDialog();
}

Thanks for reading!

Keith
Oliver Sturm - 08 Aug 2005 18:14 GMT
> An environment setting?

Exactly. The dialogs set the application's working directory, which you
can access (and set yourself) at any time via
Environment.CurrentDirectory. As long as you have only one
Open-/SaveFileDialog, that one will track its current directory itself,
but if you want to find out the most recently used directory to
synchronize multiple dialog components, you need to use the Environment
property.

               Oliver Sturm
Signature

omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog

Keith - 08 Aug 2005 21:24 GMT
Oliver,

Thanks for the reply.  I'm not tracking multiple dialogs, but rather doing a
look-ahead to generate appropriate filenames (Document1, Document2, etc.) to
using in the FileDialog.

Regardless, your tip will work great for me.  I suppose if I want to persist
this directory between instances of my app I'll need to write it out to the
Registry or something.

Thanks again!

Keith

>> An environment setting?
>
[quoted text clipped - 7 lines]
>
>                Oliver Sturm
Keith - 09 Aug 2005 00:34 GMT
> Regardless, your tip will work great for me.  I suppose if I want to
> persist
> this directory between instances of my app I'll need to write it out to
> the Registry or something.

Ok,

Maybe this won't work so well for me.  Environment.CurrentDirectory is only
updated after the dialog is shown once; then it contains the last dir used
by the dialog.  Before that, it contains the dir from which the process was
started.  However, when the dialog is shown, it opens to the correct dir
(the last one used, even between instances of the app) regardless.

So where does the dialog persist this information?  It can't be using
CurrentDirectory, since it doesn't contain the correct information; it must
be stored somewhere else.  I'd like to be able to get the info right from
the source.

Any ideas?

Keith
Oliver Sturm - 09 Aug 2005 10:30 GMT
> So where does the dialog persist this information?  It can't be using
> CurrentDirectory, since it doesn't contain the correct information; it must
> be stored somewhere else.  I'd like to be able to get the info right from
> the source.

There's a registry key at
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32,
which is used for this purpose. Maybe it's documented somewhere, but
I've never tried to read and parse this information. It's categorized by
file type, so it might not be that useful to your own application -
maybe it would be better if you just stored away your own last path and
set it again on restart.

               Oliver Sturm
Signature

omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog

Keith - 09 Aug 2005 16:55 GMT
Oliver,

Thanks for all the suggestions!

K

>> So where does the dialog persist this information?  It can't be using
>> CurrentDirectory, since it doesn't contain the correct information; it
[quoted text clipped - 10 lines]
>
>                Oliver Sturm

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.