Skip to content

Crash for SaveFileDialog when using root directory #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions src/Ookii.Dialogs.Wpf/VistaFileDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
19 changes: 5 additions & 14 deletions src/Ookii.Dialogs.Wpf/VistaFolderBrowserDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down