示例#1
0
        /// <summary>
        /// Creates a shell library in a given local folder,
        /// using the given shell library name.
        /// </summary>
        /// <param name="libraryName">The name of this library</param>
        /// <param name="folderPath">The path to the local folder</param>
        /// <param name="overwrite">Override an existing library with the same name</param>
        public ShellLibrary(string libraryName, string folderPath, bool overwrite)
            : this()
        {
            if (string.IsNullOrEmpty(libraryName))
            {
                throw new ArgumentException(LocalizedMessages.ShellLibraryEmptyName, "libraryName");
            }

            if (!Directory.Exists(folderPath))
            {
                throw new DirectoryNotFoundException(LocalizedMessages.ShellLibraryFolderNotFound);
            }

            this.Name = libraryName;

            LibrarySaveOptions flags = overwrite ?
                                       LibrarySaveOptions.OverrideExisting :
                                       LibrarySaveOptions.FailIfThere;

            Guid guid = new Guid(ShellIIDGuid.IShellItem);

            IShellItem shellItemIn;

            ShellNativeMethods.SHCreateItemFromParsingName(folderPath, IntPtr.Zero, ref guid, out shellItemIn);

            nativeShellLibrary = (INativeShellLibrary) new ShellLibraryCoClass();
            nativeShellLibrary.Save(shellItemIn, libraryName, flags, out nativeShellItem);
        }
示例#2
0
        /// <summary>
        /// Creates a shell library in the Libraries Known Folder,
        /// using the given shell library name.
        /// </summary>
        /// <param name="libraryName">The name of this library</param>
        /// <param name="overwrite">Allow overwriting an existing library; if one exists with the same name</param>
        public ShellLibrary(string libraryName, bool overwrite)
            : this()
        {
            if (string.IsNullOrEmpty(libraryName))
            {
                throw new ArgumentException(LocalizedMessages.ShellLibraryEmptyName, "libraryName");
            }

            this.Name = libraryName;
            Guid guid = new Guid(ShellKFIDGuid.Libraries);

            LibrarySaveOptions flags = overwrite ?
                                       LibrarySaveOptions.OverrideExisting :
                                       LibrarySaveOptions.FailIfThere;

            nativeShellLibrary = (INativeShellLibrary) new ShellLibraryCoClass();
            nativeShellLibrary.SaveInKnownFolder(ref guid, libraryName, flags, out nativeShellItem);
        }
示例#3
0
        /// <summary>
        /// Creates a shell library in a given local folder,
        /// using the given shell library name.
        /// </summary>
        /// <param name="libraryName">The name of this library</param>
        /// <param name="folderPath">The path to the local folder</param>
        /// <param name="overwrite">Override an existing library with the same name</param>
        public ShellLibrary(string libraryName, string folderPath, bool overwrite)
            : this()
        {
            if (string.IsNullOrEmpty(libraryName))
            {
                throw new ArgumentException("Library Name Empty!", "libraryName");
            }

            if (!Directory.Exists(folderPath))
            {
                throw new DirectoryNotFoundException("Library Not Found!");
            }

            this.Name = libraryName;
            LibrarySaveOptions flags       = overwrite ? LibrarySaveOptions.OverrideExisting : LibrarySaveOptions.FailIfThere;
            IShellItem         shellItemIn = Shell32.SHCreateItemFromParsingName(folderPath, IntPtr.Zero, new Guid(InterfaceGuids.IShellItem));

            nativeShellLibrary = (INativeShellLibrary) new ShellLibraryCoClass();
            nativeShellLibrary.Save(shellItemIn, libraryName, flags, out m_ComInterface);
        }