/// <summary> /// Converts a <see cref="IntPtr"/> formated PIDL representation /// into a path representation 'C:\'. /// /// The memory of the PIDL passed in must be freed /// (<see cref="Marshal.FreeCoTaskMem"/>) by the caller. /// </summary> /// <param name="pidl"></param> /// <param name="pathType"></param> /// <returns></returns> public static string GetPathFromPIDL(IntPtr pidl, TypOfPath pathType) { if (pidl != default(IntPtr)) { using (var parentPath = KnownFolderHelper.FromPIDL(pidl)) { if (pathType == TypOfPath.LogicalPath) { if (parentPath != null) { var props = KnownFolderHelper.GetFolderProperties(parentPath.Obj); if (props != null) { return(string.Format("{0}{1}{2}{3}", KF_IID.IID_Prefix, "{", props.FolderId, "}")); } } } } var sb = new StringBuilder(NativeMethods.MAX_PATH); if (NativeMethods.SHGetPathFromIDList(pidl, sb) == true) { return(sb.ToString()); } } return(null); }
/// <summary> /// Converts a <see cref="IdList"/> formated PIDL representation /// into a path (parse name) representation 'C:\'. /// </summary> /// <param name="idList"></param> /// <param name="pathType"></param> /// <returns></returns> public static string GetPathFromPIDL(IdList idList, TypOfPath pathType) { IntPtr pidl = PidlManager.IdListToPidl(idList); try { return(PidlManager.GetPathFromPIDL(pidl, pathType)); } finally { Marshal.FreeCoTaskMem(pidl); } }