Esempio n. 1
0
        /// <summary>
        ///  Get the path for the given known folder Guid.
        /// </summary>
        public static string GetKnownFolderPath(Guid folderIdentifier, KnownFolderFlags flags = KnownFolderFlags.Default)
        {
            Imports.SHGetKnownFolderPath(ref folderIdentifier, flags, EmptySafeHandle.Instance, out string path)
            .ThrowIfFailed();

            return(path);
        }
Esempio n. 2
0
        /// <summary>
        ///  Get the Shell item id for the given known folder Guid.
        /// </summary>
        public static ItemIdList GetKnownFolderId(Guid folderIdentifier, KnownFolderFlags flags = KnownFolderFlags.Default)
        {
            Imports.SHGetKnownFolderIDList(ref folderIdentifier, flags, EmptySafeHandle.Instance, out ItemIdList id)
            .ThrowIfFailed();

            return(id);
        }
Esempio n. 3
0
        private static string GetPath(KnownFolder knownFolder, KnownFolderFlags flags,
                                      bool defaultUser)
        {
            int result = SHGetKnownFolderPath(new Guid(KnownFoldersGuid[(int)knownFolder]),
                                              (uint)flags, new IntPtr(defaultUser ? -1 : 0), out IntPtr outPath);

            return(result switch
            {
Esempio n. 4
0
        private void SetPath(KnownFolderFlags flags, string path)
        {
            int result = SHSetKnownFolderPath(Type.GetGuid(), (uint)flags, Identity.Token, path);

            if (result < 0)
            {
                throw new ExternalException("Cannot set the known folder path. It may not be available on this system.",
                                            result);
            }
        }
Esempio n. 5
0
        private static string GetPath(KnownFolder knownFolder, KnownFolderFlags flags, bool defaultUser)
        {
            int result = SHGetKnownFolderPath(new Guid(KnownFolderGuids[(int) knownFolder]), (uint) flags, new IntPtr(defaultUser ? -1 : 0), out IntPtr outPath);
            if (result >= 0)
            {
                string path = Marshal.PtrToStringUni(outPath);
                Marshal.FreeCoTaskMem(outPath);
                return path;
            }

            throw new ExternalException("Unable to retrieve the known folder path. It may not be available on this system.", result);
        }
Esempio n. 6
0
        private static string GetPath(Guid guid, KnownFolderFlags flags)
        {
            int result = SHGetKnownFolderPath(guid, (uint)flags, WindowsIdentity.GetCurrent().Token, out IntPtr outPath);

            if (result >= 0)
            {
                string path = Marshal.PtrToStringUni(outPath);
                Marshal.FreeCoTaskMem(outPath);
                return(path);
            }
            return("");
        }
Esempio n. 7
0
 private static string GetPath(KnownFolder knownFolder, KnownFolderFlags flags,
     bool defaultUser)
 {
     IntPtr outPath;
     int result = SHGetKnownFolderPath(new Guid(_knownFolderGuids[(int)knownFolder]), (uint)flags, new IntPtr(defaultUser ? -1 : 0), out outPath);
     if (result >= 0)
     {
         return Marshal.PtrToStringUni(outPath);
     }
     else
     {
         throw new ExternalException("Unable to retrieve the known folder path. It may not " + "be available on this system.", result);
     }
 }
Esempio n. 8
0
        private static string GetPath(KnownFolder knownFolder, KnownFolderFlags flags,
                                      bool defaultUser)
        {
            var result = SHGetKnownFolderPath(new Guid(KnownFoldersGuid[(int)knownFolder]),
                                              (uint)flags, new IntPtr(defaultUser ? -1 : 0), out var outPath);

            if (result >= 0)
            {
                return(Marshal.PtrToStringUni(outPath));
            }

            throw new ExternalException("Unable to retrieve the known folder path. It may not "
                                        + "be available on this system.", result);
        }
Esempio n. 9
0
        // ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------

        private string GetPath(KnownFolderFlags flags)
        {
            IntPtr outPath;
            int    result = SHGetKnownFolderPath(Type.GetGuid(), (uint)flags, Identity.Token, out outPath);

            if (result >= 0)
            {
                return(Marshal.PtrToStringUni(outPath));
            }
            else
            {
                throw new ExternalException("Cannot get the known folder path. It may not be available on this system.",
                                            result);
            }
        }
Esempio n. 10
0
        private static string GetPath(KnownFolder knownFolder, KnownFolderFlags flags,
                                      bool defaultUser)
        {
            IntPtr outPath;
            int    result = SHGetKnownFolderPath(new Guid(_knownFolderGuids[(int)knownFolder]),
                                                 (uint)flags, new IntPtr(defaultUser ? -1 : 0), out outPath);

            if (result >= 0)
            {
                return(Marshal.PtrToStringUni(outPath));
            }
            else
            {
                throw new Exception($"Unable to retrieve the known folder path. It may not be available on this system. Error: {result}");
            }
        }
 public static extern HResult SHGetKnownFolderIDList(
     ref Guid rfid,
     KnownFolderFlags dwFlags,
     SafeHandle hToken,
     out ItemIdList ppidl);
 public static extern HResult SHGetKnownFolderPath(
     ref Guid rfid,
     KnownFolderFlags dwFlags,
     SafeHandle hToken,
     out string ppszPath);