diff --git a/src/Ookii.Dialogs.Wpf/VistaFileDialog.cs b/src/Ookii.Dialogs.Wpf/VistaFileDialog.cs index d72a137..9de611e 100644 --- a/src/Ookii.Dialogs.Wpf/VistaFileDialog.cs +++ b/src/Ookii.Dialogs.Wpf/VistaFileDialog.cs @@ -633,17 +633,13 @@ internal virtual void SetDialogProperties(Ookii.Dialogs.Wpf.Interop.IFileDialog // Set the default file name if( !(_fileNames == null || _fileNames.Length == 0 || string.IsNullOrEmpty(_fileNames[0])) ) { - string parent = Path.GetDirectoryName(_fileNames[0]); - if( parent == null || !Directory.Exists(parent) ) - { - dialog.SetFileName(_fileNames[0]); - } - else - { - string folder = Path.GetFileName(_fileNames[0]); - dialog.SetFolder(NativeMethods.CreateItemFromParsingName(parent)); - dialog.SetFileName(folder); - } + dialog.SetFileName(_fileNames[0]); + } + + // Set the default directory + if( Directory.Exists(_initialDirectory) ) + { + dialog.SetFolder(NativeMethods.CreateItemFromParsingName(_initialDirectory)); } // Set the filter @@ -668,13 +664,6 @@ internal virtual void SetDialogProperties(Ookii.Dialogs.Wpf.Interop.IFileDialog dialog.SetDefaultExtension(_defaultExt); } - // Initial directory - if( !string.IsNullOrEmpty(_initialDirectory) ) - { - Ookii.Dialogs.Wpf.Interop.IShellItem item = NativeMethods.CreateItemFromParsingName(_initialDirectory); - dialog.SetDefaultFolder(item); - } - if( !string.IsNullOrEmpty(_title) ) { dialog.SetTitle(_title); diff --git a/src/Ookii.Dialogs.Wpf/VistaFolderBrowserDialog.cs b/src/Ookii.Dialogs.Wpf/VistaFolderBrowserDialog.cs index 314f3a8..cf21765 100644 --- a/src/Ookii.Dialogs.Wpf/VistaFolderBrowserDialog.cs +++ b/src/Ookii.Dialogs.Wpf/VistaFolderBrowserDialog.cs @@ -364,22 +364,13 @@ private void SetDialogProperties(Ookii.Dialogs.Wpf.Interop.IFileDialog dialog) } } - dialog.SetOptions(NativeMethods.FOS.FOS_PICKFOLDERS | NativeMethods.FOS.FOS_FORCEFILESYSTEM | NativeMethods.FOS.FOS_FILEMUSTEXIST | _options); - - if ( !string.IsNullOrEmpty(_selectedPath) ) + // Set the default directory + if (Directory.Exists(_selectedPath)) { - string parent = Path.GetDirectoryName(_selectedPath); - if( parent == null || !Directory.Exists(parent) ) - { - dialog.SetFileName(_selectedPath); - } - else - { - string folder = Path.GetFileName(_selectedPath); - dialog.SetFolder(NativeMethods.CreateItemFromParsingName(parent)); - dialog.SetFileName(folder); - } + dialog.SetFolder(NativeMethods.CreateItemFromParsingName(_selectedPath)); } + + dialog.SetOptions(NativeMethods.FOS.FOS_PICKFOLDERS | NativeMethods.FOS.FOS_FORCEFILESYSTEM | NativeMethods.FOS.FOS_FILEMUSTEXIST); } private void GetResult(IFileDialog dialog)