/// <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); } Name = libraryName; ShellNativeMethods.LibrarySaveOptions flags = overwrite ? ShellNativeMethods.LibrarySaveOptions.OverrideExisting : ShellNativeMethods.LibrarySaveOptions.FailIfThere; Guid guid = new Guid(ShellIIDGuid.IShellItem); ShellNativeMethods.SHCreateItemFromParsingName(folderPath, IntPtr.Zero, ref guid, out IShellItem shellItemIn); nativeShellLibrary = (INativeShellLibrary) new ShellLibraryCoClass(); nativeShellLibrary.Save(shellItemIn, libraryName, flags, out nativeShellItem); }
/// <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"); } Name = libraryName; Guid guid = new Guid(ShellKFIDGuid.Libraries); ShellNativeMethods.LibrarySaveOptions flags = overwrite ? ShellNativeMethods.LibrarySaveOptions.OverrideExisting : ShellNativeMethods.LibrarySaveOptions.FailIfThere; nativeShellLibrary = (INativeShellLibrary) new ShellLibraryCoClass(); nativeShellLibrary.SaveInKnownFolder(ref guid, libraryName, flags, out nativeShellItem); }
/// <summary> /// Creates a shell library in a given Known Folder, /// using the given shell library name. /// </summary> /// <param name="libraryName">The name of this library</param> /// <param name="sourceKnownFolder">The known folder</param> /// <param name="overwrite">Override an existing library with the same name</param> public ShellLibrary(string libraryName, IKnownFolder sourceKnownFolder, bool overwrite) : this() { if (string.IsNullOrEmpty(libraryName)) { throw new ArgumentException(LocalizedMessages.ShellLibraryEmptyName, nameof(libraryName)); } this.knownFolder = sourceKnownFolder; this.Name = libraryName; Guid guid = this.knownFolder.FolderId; ShellNativeMethods.LibrarySaveOptions flags = overwrite ? ShellNativeMethods.LibrarySaveOptions.OverrideExisting : ShellNativeMethods.LibrarySaveOptions.FailIfThere; this.nativeShellLibrary = (INativeShellLibrary) new ShellLibraryCoClass(); this.nativeShellLibrary.SaveInKnownFolder(ref guid, libraryName, flags, out this.nativeShellItem); }