Пример #1
0
        /// <summary>
        /// Returns a list of name and guid pairs for all known folders.
        /// </summary>
        /// <returns>A <see cref="T:System.Collections.Generic.SortedList`2"/>.
        /// </returns>
        /// <remarks>The
        /// list returned by this method is sorted by folder name.</remarks>
        public static SortedList <string, Guid> GetAllFolders()
        {
            SortedList <string, Guid> s = FolderIdentifiers.GetAllFolders();

            return(s);
        }
        /// <summary>
        /// Populates a structure that contains
        /// this known folder's properties.
        /// </summary>
        private void GetFolderProperties()
        {
            SafeNativeMethods.NativeFolderDefinition nativeFolderDefinition;
            FolderProperties _definition =
                new FolderProperties();

            this._knownFolder.GetFolderDefinition(
                out nativeFolderDefinition);

            try
            {
                _definition.category      = nativeFolderDefinition.category;
                _definition.canonicalName =
                    Marshal.PtrToStringUni(nativeFolderDefinition.name);
                _definition.description =
                    Marshal.PtrToStringUni(nativeFolderDefinition.description);
                _definition.parentId     = nativeFolderDefinition.parentId;
                _definition.relativePath =
                    Marshal.PtrToStringUni(nativeFolderDefinition.relativePath);
                _definition.parsingName =
                    Marshal.PtrToStringUni(nativeFolderDefinition.parsingName);
                _definition.tooltipResourceId =
                    Marshal.PtrToStringUni(nativeFolderDefinition.tooltip);
                _definition.localizedNameResourceId =
                    Marshal.PtrToStringUni(nativeFolderDefinition.localizedName);
                _definition.iconResourceId =
                    Marshal.PtrToStringUni(nativeFolderDefinition.icon);
                _definition.security =
                    Marshal.PtrToStringUni(nativeFolderDefinition.security);
                _definition.fileAttributes =
                    (System.IO.FileAttributes)nativeFolderDefinition.attributes;
                _definition.definitionOptions =
                    nativeFolderDefinition.definitionOptions;

                _definition.folderTypeId =
                    nativeFolderDefinition.folderTypeId;

                _definition.folderType = FolderTypes.GetFolderType(
                    _definition.folderTypeId);

                bool?pathExists;

                _definition.path       = GetPath(out pathExists);
                _definition.pathExists = pathExists;

                _definition.redirection =
                    _knownFolder.GetRedirectionCapabilities();

                // Turn tooltip, localized name and icon resource IDs
                // into the actual resources.
                _definition.tooltip = Helpers.GetStringResource(
                    _definition.tooltipResourceId);

                _definition.icon = Helpers.GetIcon(
                    _definition.iconResourceId);

                _definition.localizedName = Helpers.GetStringResource(
                    _definition.localizedNameResourceId);

                _definition.folderId = _knownFolder.GetId();
                _definition.name     = FolderIdentifiers.NameForGuid(
                    _definition.folderId);

                if (_definition.parentId != Guid.Empty)
                {
                    _definition.parent = FolderIdentifiers.NameForGuid(
                        _definition.parentId);
                }
                else
                {
                    _definition.parent = String.Empty;
                }

                properties = _definition;
            }
            finally
            {
                // Clean up memory.
                Marshal.FreeCoTaskMem(nativeFolderDefinition.name);
                Marshal.FreeCoTaskMem(nativeFolderDefinition.description);
                Marshal.FreeCoTaskMem(nativeFolderDefinition.relativePath);
                Marshal.FreeCoTaskMem(nativeFolderDefinition.parsingName);
                Marshal.FreeCoTaskMem(nativeFolderDefinition.tooltip);
                Marshal.FreeCoTaskMem(nativeFolderDefinition.localizedName);
                Marshal.FreeCoTaskMem(nativeFolderDefinition.icon);
                Marshal.FreeCoTaskMem(nativeFolderDefinition.security);
            }
        }