tags:

views:

614

answers:

2

I'd like a SaveFileDialog with the following behavior:

  • The first time you open it, it goes to "My Documents".

  • Afterwards, it goes to the last selected folder. What's the best way to accomplish this?

If I don't set the InitialDirectory, it goes to the exe's directory - which is not what I want. It rememebers the last selected directory though - even between executions.

If I set the InitialDirectory, it does not remember the last selected directory. Of course, I could save the last selected directory in the registry :( but I am looking for a better solution.

      SaveFileDialog dialog = new SaveFileDialog();
      //??? dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
      dialog.ShowDialog();

Any advice?

+4  A: 

You need to set the RestoreDirectory to true as well as the InitialDirectory property.

Andrew Hare
Ah, that's what RestoreDirectory is for ....
tom greene
Also see this thread, where programmer says that setting "RestoreDirectory" to true doesn't help:http://discuss.joelonsoftware.com/default.asp?dotnet.12.424113.2
SLA80
really? Doesn't work for me. It just always navigates to the InitialDirectory?
Patrick Klug
A: 

I did some testing with .NET 2.0 and it seems if I set FileName to anything other than a literal string it doesn't work. When I use a method or accesstor to set the property the initial directory is ignored.

Icono123