From 934cc3bafd376943394b86177d05d86734ca94cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20Nieto=20S=C3=A1nchez?= Date: Wed, 28 Dec 2016 18:15:57 +0100 Subject: [PATCH] Environment.CurrentDirectory is modified after call to GetOpenFileName | GetSaveFileName call. --- src/Windows/Avalonia.Win32/SystemDialogImpl.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Windows/Avalonia.Win32/SystemDialogImpl.cs b/src/Windows/Avalonia.Win32/SystemDialogImpl.cs index f153b26412..1941d6b60e 100644 --- a/src/Windows/Avalonia.Win32/SystemDialogImpl.cs +++ b/src/Windows/Avalonia.Win32/SystemDialogImpl.cs @@ -88,9 +88,16 @@ namespace Avalonia.Win32 var pofn = &ofn; + // We should save the current directory to restore it later. + var currentDirectory = Environment.CurrentDirectory; + var res = dialog is OpenFileDialog ? UnmanagedMethods.GetOpenFileName(new IntPtr(pofn)) : UnmanagedMethods.GetSaveFileName(new IntPtr(pofn)); + + // Restore the old current directory, since GetOpenFileName and GetSaveFileName change it after they're called + Environment.CurrentDirectory = currentDirectory; + if (!res) return null; if (dialog?.Filters.Count > 0)