Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the FileDialog.RestoreDirectory Property actually do?

People also ask

Which of the following are FileDialog class?

FileDialog is an abstract class that contains common behavior for the OpenFileDialog and SaveFileDialog classes. It is not intended to be used directly but contains common behavior for those two classes. You cannot create an instance of FileDialog.

What is initial directory?

The InitialDirectory property is typically set using one of the following sources: A path that was previously used in the program, perhaps retained from the last directory or file operation. A path read from a persistent source, such as an application setting, a Registry or a string resource in the application.


IIRC, in windows XP when you press Save on a SaveFileDialog (or Open on a OpenFileDialog) the directory where the file is saved (or opened), is set as the new current working directory (the one in Environment.CurrentDirectory).

By setting FileDialog.RestoreDirectory = true, when you close the FileDialog the original working directory is restored.

In Windows Vista/Seven the behavior is always as FileDialog.RestoreDirectory = true (yes, even if you set it to false...).


An annoyig quirk of the original implementation was that after you made your selection the current directory of your app changed to that folder, meaning that if you expected File operations to be relative to your app folder, it now failed.

This meant it was common practice to add code to capture the current folder before using he dialog, and restore it afterwards.

This was fixed, so it can do this for you, but changing the default behaviour might have broken code tha relied on the quirk. So you need to enable it manually via this property.