Search code examples
wpfopenfiledialog

Why OpenFileDialog RestoreDirectory not implemented?


I'm using Microsoft.Win32.OpenFileDialog in my wpf application since it is stated as equivalent here; http://msdn.microsoft.com/en-us/library/ms750559.aspx

I set the RestoreDirectory property to true, but it has no effect. When I wait on the property it is documented that "This property is not implemented."

So how can I achieve this task without implementing the logic myself?


Solution

  • RestoreDirectory is automaticly implemented.

    string fileName = string.Empty;
    
    var dialog = new OpenFileDialog();
    dialog.InitialDirectory = @"c:\test";
    if (dialog.ShowDialog() == true)
        fileName = dialog.FileName;
    

    if you don't specify InitialDirectory it will open last selected file's directory