Esempio n. 1
0
        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);
        }