What does the FileDialog.RestoreDirectory Property actually do?

邮差的信 提交于 2019-11-30 00:17:58

问题


I've read about the property on MSDN, but I still don't understand what it does.

Gets or sets a value indicating whether the dialog box restores the current directory before closing.

What exactly does that mean? What does 'restoring' the current directory actually do? Thanks for the help.


回答1:


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...).




回答2:


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.




回答3:


If it's set to true the file dialog will always open the default file path (InitialDirectory property).




回答4:


When you can select a directory when using the dialog box, next use of the dialog will open in the last used directory. Using this option will restore the original directory.




回答5:


Here, I am talking about WinForms FileDialog only, WPF FileDialog may have different behaviour.

For Win XP, the current directory is changed during the use of dialog.

For multi-threaded application, this must be aware. It is easy to proof by running a loop in a new thread to check if current directory is changed during the use of dialog, when switching to another folder.

For Win 7 / mono, the current directory is not changed during or after using the dialog.

Therefore Win 7 / mono: RestoreDirectory property is not needed.



来源:https://stackoverflow.com/questions/4353487/what-does-the-filedialog-restoredirectory-property-actually-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!