/// <summary> /// Get the Shell item id for the given known folder Guid. /// </summary> public static ItemIdList GetKnownFolderId(Guid folderIdentifier, KNOWN_FOLDER_FLAG flags = KNOWN_FOLDER_FLAG.KF_FLAG_DEFAULT) { HRESULT hr = Imports.SHGetKnownFolderIDList(folderIdentifier, flags, EmptySafeHandle.Instance, out ItemIdList id); if (hr != HRESULT.S_OK) { throw Errors.GetIoExceptionForHResult(hr, folderIdentifier.ToString()); } return(id); }
public static string GetKnownFolderPath(Guid folderIdentifier, KNOWN_FOLDER_FLAG flags = KNOWN_FOLDER_FLAG.KF_FLAG_DEFAULT) { string path; HRESULT hr = Direct.SHGetKnownFolderPath(folderIdentifier, flags, EmptySafeHandle.Instance, out path); if (hr != HRESULT.S_OK) { throw ErrorHelper.GetIoExceptionForHResult(hr, folderIdentifier.ToString()); } return(path); }
/// <summary> /// Gets the path of a folder identified by a CSIDL value. /// </summary> /// <param name="rfid"> /// A <see cref="Guid"/> value that identifies the folder whose path is to be retrieved. /// As defined in <see cref="KNOWNFOLDERID"/>. /// </param> /// <param name="dwFlags">Flags that specify special retrieval options. This value can be 0; otherwise, one or more of the <see cref="KNOWN_FOLDER_FLAG"/> values.</param> /// <param name="hToken"> /// An access token that represents a particular user. If this parameter is NULL, which is the most common usage, the function requests the known folder for the current user. /// Assigning the hToken parameter a value of -1 indicates the Default User. /// Microsoft Windows 2000 and earlier: Always set this parameter to NULL. /// Windows XP and later: This parameter is usually set to NULL, but you might need to assign a non-NULL value to hToken for those folders that can have multiple users but are treated as belonging to a single user.The most commonly used folder of this type is Documents. /// </param> /// <returns> /// The returned path does not include a trailing backslash. For example, "C:\Users" is returned rather than "C:\Users\". /// </returns> /// <remarks> /// As of Windows Vista, this function is merely a wrapper for <see cref="SHGetKnownFolderPath(Guid, KNOWN_FOLDER_FLAG, IntPtr, out char*)"/>. /// The returned path does not include a trailing backslash. /// For example, "C:\Users" is returned rather than "C:\Users\". /// </remarks> public static unsafe string SHGetKnownFolderPath(Guid rfid, KNOWN_FOLDER_FLAG dwFlags = KNOWN_FOLDER_FLAG.None, IntPtr hToken = default(IntPtr)) { char* pszPath; SHGetKnownFolderPath(rfid, dwFlags, hToken, out pszPath).ThrowOnFailure(); try { return new string(pszPath); } finally { Marshal.FreeCoTaskMem((IntPtr)pszPath); } }
/// <summary> /// Gets the path of a folder identified by a CSIDL value. /// </summary> /// <param name="rfid"> /// A <see cref="Guid"/> value that identifies the folder whose path is to be retrieved. /// As defined in <see cref="KNOWNFOLDERID"/>. /// </param> /// <param name="dwFlags">Flags that specify special retrieval options. This value can be 0; otherwise, one or more of the <see cref="KNOWN_FOLDER_FLAG"/> values.</param> /// <param name="hToken"> /// An access token that represents a particular user. If this parameter is NULL, which is the most common usage, the function requests the known folder for the current user. /// Assigning the hToken parameter a value of -1 indicates the Default User. /// Microsoft Windows 2000 and earlier: Always set this parameter to NULL. /// Windows XP and later: This parameter is usually set to NULL, but you might need to assign a non-NULL value to hToken for those folders that can have multiple users but are treated as belonging to a single user.The most commonly used folder of this type is Documents. /// </param> /// <returns> /// The returned path does not include a trailing backslash. For example, "C:\Users" is returned rather than "C:\Users\". /// </returns> /// <remarks> /// As of Windows Vista, this function is merely a wrapper for <see cref="SHGetKnownFolderPath(Guid, KNOWN_FOLDER_FLAG, IntPtr, out char*)"/>. /// The returned path does not include a trailing backslash. /// For example, "C:\Users" is returned rather than "C:\Users\". /// </remarks> public static unsafe string SHGetKnownFolderPath(Guid rfid, KNOWN_FOLDER_FLAG dwFlags = KNOWN_FOLDER_FLAG.None, IntPtr hToken = default(IntPtr)) { char *pszPath; SHGetKnownFolderPath(rfid, dwFlags, hToken, out pszPath).ThrowOnFailure(); try { return(new string(pszPath)); } finally { Marshal.FreeCoTaskMem((IntPtr)pszPath); } }
public static extern unsafe HResult SHGetKnownFolderPath( [MarshalAs(UnmanagedType.LPStruct)] Guid rfid, KNOWN_FOLDER_FLAG dwFlags, IntPtr hToken, out char *ppszPath); // Do NOT use [Friendly(Array)] here, because an "out byte[]" overload would produce a memory leak, since freeing memory would require a pointer no one has.
public static extern unsafe HResult SHGetKnownFolderIDList( [MarshalAs(UnmanagedType.LPStruct)] Guid rfid, KNOWN_FOLDER_FLAG dwFlags, IntPtr hToken, out ITEMIDLIST *pidl);
public static extern int SHGetKnownFolderPath([MarshalAs(UnmanagedType.LPStruct)] Guid rfid, KNOWN_FOLDER_FLAG dwFlags, IntPtr hToken, out string pszPath);
public static extern int SHGetKnownFolderIDList([MarshalAs(UnmanagedType.LPStruct)] Guid rfid, KNOWN_FOLDER_FLAG dwFlags, IntPtr hToken, out IntPtr ppidl);
internal static extern HRESULT SHGetKnownFolderPath([MarshalAs(UnmanagedType.LPStruct)] Guid rfid, KNOWN_FOLDER_FLAG dwFlags, IntPtr hToken, out IntPtr pszPath);
public static extern unsafe HResult SHGetKnownFolderIDList( [MarshalAs(UnmanagedType.LPStruct)] Guid rfid, KNOWN_FOLDER_FLAG dwFlags, IntPtr hToken, out ITEMIDLIST* pidl);
public static extern int SHGetKnownFolderIDList([MarshalAs(UnmanagedType.LPStruct)] Guid rfid, KNOWN_FOLDER_FLAG dwFlags, IntPtr hToken, out IntPtr ppidl);
internal static extern void SHGetKnownFolderPath([In] ref Guid rfid, [In] KNOWN_FOLDER_FLAG dwFlags, [In] IntPtr hToken, [Out, MarshalAs(UnmanagedType.LPWStr)] out string ppszPath);
internal static extern void SHCreateItemInKnownFolder([In] ref Guid kfid, [In] KNOWN_FOLDER_FLAG dwKFFlags, [In, MarshalAs(UnmanagedType.LPWStr)] string pszItem, [In] ref Guid riid, [Out, MarshalAs(UnmanagedType.Interface)] out object ppv);
public static extern HRESULT SHGetKnownFolderIDList( [MarshalAs(UnmanagedType.LPStruct)] Guid rfid, KNOWN_FOLDER_FLAG dwFlags, SafeHandle hToken, out ItemIdList ppidl);
public static extern HRESULT SHGetKnownFolderPath( [MarshalAs(UnmanagedType.LPStruct)] Guid rfid, KNOWN_FOLDER_FLAG dwFlags, SafeHandle hToken, out string ppszPath);
public static extern unsafe HResult SHGetKnownFolderPath( [MarshalAs(UnmanagedType.LPStruct)] Guid rfid, KNOWN_FOLDER_FLAG dwFlags, IntPtr hToken, out char* ppszPath); // Do NOT use [Friendly(Array)] here, because an "out byte[]" overload would produce a memory leak, since freeing memory would require a pointer no one has.
// public static extern int SHGetKnownFolderPath(Guid rfid, KNOWN_FOLDER_FLAG dwFlags, IntPtr hToken, StringBuilder ppszPath); // public static extern int SHGetKnownFolderPath(Guid rfid, KNOWN_FOLDER_FLAG dwFlags, IntPtr hToken, out string ppszPath); public static extern int SHGetKnownFolderPath(Guid rfid, KNOWN_FOLDER_FLAG dwFlags, IntPtr hToken, out IntPtr ppszPath);
public static extern int SHGetKnownFolderPath([MarshalAs(UnmanagedType.LPStruct)] Guid rfid, KNOWN_FOLDER_FLAG dwFlags, IntPtr hToken, out string pszPath);