Add try, finally to SHOpenFolderAndSelectItems

This commit is contained in:
Jaex 2016-06-29 00:02:06 +03:00
parent 3425e167db
commit a8636cbf39

View file

@ -477,15 +477,18 @@ public static bool FlashWindowEx(Form frm, uint flashCount = uint.MaxValue)
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);
try
{
SHOpenFolderAndSelectItems(pidl, 0, IntPtr.Zero, 0);
}
finally
{
ILFree(pidl);
}
}
}
}