Discussion:
OpenFileDialog - Disable Storage of Selected Folder
(too old to reply)
Dan
2009-12-01 22:26:37 UTC
Permalink
The OpenFileDialog in .NET has the side effect of remembering the
folder from it last use, such that the next time an OpenFileDialog is
used, it will default to the prior used folder by default.

I would like to use OpenFileDialog without this feature ... so I need
to figure out where OpenFileDialog is reading the last used folder
setting.

A few older posts directed me to the registry, I tried saving and
restoring values under CurrentUser\Software\Microsoft\Windows
\CurrentVersion\Explorer\ComDlg32 but this did not work.

I also tried working with the Environment.CurrentDirectory variable
only to discover that the OpenFileDialog is getting its default value
somewhere else.

Does anyone know where to find the default folder value that
OpenFileDialog uses by default?

Thanks,

Dan
Herfried K. Wagner [MVP]
2009-12-02 03:29:22 UTC
Permalink
Post by Dan
The OpenFileDialog in .NET has the side effect of remembering the
folder from it last use, such that the next time an OpenFileDialog is
used, it will default to the prior used folder by default.
I would like to use OpenFileDialog without this feature ... so I need
to figure out where OpenFileDialog is reading the last used folder
setting.
Just set the component's 'InitialDirectory' property to the path you
want to be used as the initial directory selection.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Dan
2009-12-02 13:45:42 UTC
Permalink
On Dec 1, 9:29 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
Post by Herfried K. Wagner [MVP]
Post by Dan
The OpenFileDialog in .NET has the side effect of remembering the
folder from it last use, such that the next time an OpenFileDialog is
used, it will default to the prior used folder by default.
I would like to use OpenFileDialog without this feature ... so I need
to figure out where OpenFileDialog is reading the last used folder
setting.
Just set the component's 'InitialDirectory' property to the path you
want to be used as the initial directory selection.
--
  M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
  V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
I can not set the InitialDirectory property to solve my problem. I
have an application with about 50 OpenFileDialogs.

I have been asked to add an OpenFileDialog that will not affect all
the other OpenFileDialogs. So, I can only make the code change on one
form.

So far, I have not had much luck in arguing away the requirement. If I
could figure out where OpenFileDialog stores its last used path, I
would be able to solve the problem, but this task appears to be very
difficult.
Herfried K. Wagner [MVP]
2009-12-03 02:34:46 UTC
Permalink
Post by Dan
Post by Herfried K. Wagner [MVP]
Post by Dan
The OpenFileDialog in .NET has the side effect of remembering the
folder from it last use, such that the next time an OpenFileDialog is
used, it will default to the prior used folder by default.
I would like to use OpenFileDialog without this feature ... so I need
to figure out where OpenFileDialog is reading the last used folder
setting.
Just set the component's 'InitialDirectory' property to the path you
want to be used as the initial directory selection.
I can not set the InitialDirectory property to solve my problem. I
have an application with about 50 OpenFileDialogs.
I have been asked to add an OpenFileDialog that will not affect all
the other OpenFileDialogs. So, I can only make the code change on one
form.
Sorry, I do not understand that. Do you want all openfiledialog
components to be affected or not? What exactly do you want to achieve?
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Dan
2009-12-03 21:19:17 UTC
Permalink
On Dec 2, 8:34 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
Post by Dan
Post by Herfried K. Wagner [MVP]
TheOpenFileDialogin .NET has the side effect of remembering the
folder from it last use, such that the next time anOpenFileDialogis
used, it will default to the prior used folder by default.
I would like to useOpenFileDialogwithout this feature ... so I need
to figure out whereOpenFileDialogis reading the last used folder
setting.
Just set the component's 'InitialDirectory' property to the path you
want to be used as the initial directory selection.
I can not set the InitialDirectory property to solve my problem. I
have an application with about 50 OpenFileDialogs.
I have been asked to add anOpenFileDialogthat will not affect all
the other OpenFileDialogs. So, I can only make the code change on one
form.
Sorry, I do not understand that.  Do you want allopenfiledialog
components to be affected or not?  What exactly do you want to achieve?
--
  M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
  V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Yes, all other OpenFileDialogs should not be affected, by the new
OpenFileDialog that I need to add.

Here is how I could achieve this functionality:

string SomePath = GetOpenFileDialogPathFromStorage()

Run My New OpenFileDialog

SaveOpenFileDialogPath( SomePath )

The problem is that I can not seem to figure out what location the
OpenFileDialog uses to store the path that it "remembers" between
uses.

Danke

Dan
Jeff Johnson
2009-12-08 15:07:07 UTC
Permalink
Post by Dan
I have been asked to add an OpenFileDialog that will not affect all
the other OpenFileDialogs. So, I can only make the code change on one
form.
Well, I was going to mention the OFN_NOCHANGEDIR constant, but after
checking MSDN it appears there's no point:

============
Restores the current directory to its original value if the user changed the
directory while searching for files.

Windows NT 4.0/2000/XP: This flag is ineffective for GetOpenFileName.
============

It looks like you'll need to add a static class to your project and give it
two properties: LastSharedOpenFileFolder and LastSpecialOpenFileFolder (call
them whatever you want, of course). Then, every time one of the 50 forms
uses an OpenFileDialog you'll set (before) and store (after) the selected
path to the "Shared" property and when he uses that one special form you'll
use the other property.

Loading...