Merge pull request #1677 from dannoe/enh-open-files-folders-filemanager

Files and folders are now opened in the default filemanager.
This commit is contained in:
Jaex 2016-06-28 23:44:13 +03:00 committed by GitHub
commit 40fc977b7d
3 changed files with 23 additions and 2 deletions

View file

@ -417,7 +417,7 @@ public static bool OpenFolder(string folderPath)
{ {
try try
{ {
Process.Start("explorer.exe", folderPath); Process.Start(folderPath);
return true; return true;
} }
catch (Exception e) catch (Exception e)
@ -439,7 +439,7 @@ public static bool OpenFolderWithFile(string filePath)
{ {
try try
{ {
Process.Start("explorer.exe", $"/select,\"{filePath}\""); NativeMethods.OpenFolderAndSelectFile(filePath);
return true; return true;
} }
catch (Exception e) catch (Exception e)

View file

@ -363,6 +363,16 @@ public static partial class NativeMethods
[DllImport("shell32.dll")] [DllImport("shell32.dll")]
public static extern IntPtr SHAppBarMessage(uint dwMessage, [In] ref APPBARDATA pData); public static extern IntPtr SHAppBarMessage(uint dwMessage, [In] ref APPBARDATA pData);
// http://stackoverflow.com/questions/14600987/code-to-open-windows-explorer-or-focus-if-exists-with-file-selected
[DllImport("shell32.dll")]
public static extern int SHOpenFolderAndSelectItems(IntPtr pidlFolder, int cild, IntPtr apidl, int dwFlags);
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr ILCreateFromPathW(string pszPath);
[DllImport("shell32.dll")]
public static extern void ILFree(IntPtr pidl);
#endregion shell32.dll #endregion shell32.dll
#region dwmapi.dll #region dwmapi.dll

View file

@ -476,5 +476,16 @@ public static bool FlashWindowEx(Form frm, uint flashCount = uint.MaxValue)
return FlashWindowEx(ref fInfo); return FlashWindowEx(ref fInfo);
} }
// http://stackoverflow.com/questions/14600987/code-to-open-windows-explorer-or-focus-if-exists-with-file-selected
public static void OpenFolderAndSelectFile(string filePath)
{
if (filePath == null)
throw new ArgumentNullException(nameof(filePath));
IntPtr pidl = ILCreateFromPathW(filePath);
SHOpenFolderAndSelectItems(pidl, 0, IntPtr.Zero, 0);
ILFree(pidl);
}
} }
} }