public static string GetPathForKnownFolder(Guid knownFolder) { if (knownFolder == default(Guid)) { return(null); } StringBuilder stringBuilder = new StringBuilder(260); if (!NativeMethods2.SHGetFolderPathEx(ref knownFolder, KF_FLAG.DEFAULT, IntPtr.Zero, stringBuilder, (uint)stringBuilder.Capacity).Succeeded) { return(null); } return(stringBuilder.ToString()); }
public static string GetPathForKnownFolder(Guid knownFolder) { if (knownFolder == default(Guid)) { return(null); } var pathBuilder = new StringBuilder(NativeMethods.MAX_PATH); HRESULT hr = NativeMethods2.SHGetFolderPathEx(ref knownFolder, 0, IntPtr.Zero, pathBuilder, (uint)pathBuilder.Capacity); // If we failed to find a path for the known folder then just ignore it. return(hr.Succeeded ? pathBuilder.ToString() : null); }
public static IShellItem2 GetShellItemForPath(string path) { if (string.IsNullOrEmpty(path)) { return(null); } Guid guid = new Guid("7e9fb0d3-919f-4307-ab2e-9b1860310c93"); object obj; HRESULT hrLeft = NativeMethods2.SHCreateItemFromParsingName(path, null, ref guid, out obj); if (hrLeft == (HRESULT)Win32Error.ERROR_FILE_NOT_FOUND || hrLeft == (HRESULT)Win32Error.ERROR_PATH_NOT_FOUND) { hrLeft = HRESULT.S_OK; obj = null; } hrLeft.ThrowIfFailed(); return((IShellItem2)obj); }
public static IShellItem2 GetShellItemForPath(string path) { if (string.IsNullOrEmpty(path)) { // Internal function. Should have verified this before calling if we cared. return(null); } Guid iidShellItem2 = new Guid(IID.ShellItem2); object unk; HRESULT hr = NativeMethods2.SHCreateItemFromParsingName(path, null, ref iidShellItem2, out unk); // Silently absorb errors such as ERROR_FILE_NOT_FOUND, ERROR_PATH_NOT_FOUND. // Let others pass through if (hr == (HRESULT)Win32Error.ERROR_FILE_NOT_FOUND || hr == (HRESULT)Win32Error.ERROR_PATH_NOT_FOUND) { hr = HRESULT.S_OK; unk = null; } hr.ThrowIfFailed(); return((IShellItem2)unk); }
internal static void SHAddToRecentDocs(IShellLinkW shellLink) { NativeMethods2.SHAddToRecentDocs_ShellLink(SHARD.LINK, shellLink); }
internal static void SHAddToRecentDocs(string path) { NativeMethods2.SHAddToRecentDocsString(SHARD.PATHW, path); }