/// <summary> /// Create a Shell Library and return a <see cref="ShellLibrary"/> object /// </summary> /// <param name="name">The library name</param> /// <param name="isPinnedToNavigationPane">Whether the library is pinned to the Explorer window navigatin Pane </param> /// <returns>A <see cref="ShellLibrary"/> object</returns> public static ShellLibrary Create(string name, bool isPinnedToNavigationPane) { IShellLibrary newLibrary = new ShellLibraryClass(); Guid libraryfolderId = new Guid(KFIDGuid.Libraries); IShellItem savesToShellItem; newLibrary.SaveInKnownFolder(ref libraryfolderId, name, Windows7.DesktopIntegration.Interop.SafeNativeMethods.LIBRARYSAVEFLAGS.LSF_OVERRIDEEXISTING, out savesToShellItem); newLibrary.Commit(); string fullName = CreateLibraryFullName(name); ShellLibrary shellLibrary = new ShellLibrary(newLibrary, fullName); Marshal.ReleaseComObject(savesToShellItem); shellLibrary.IsPinnedToNavigationPane = isPinnedToNavigationPane; return(shellLibrary); }
/// <summary> /// Create a Shell Library and return a <see cref="ShellLibrary"/> object /// </summary> /// <param name="name">The library name</param> /// <param name="folderToSaveIn">The folder (library) to add the new library to</param> /// <returns>A <see cref="ShellLibrary"/> object</returns> public static ShellLibrary Create(string name, string folderToSaveIn) { IShellLibrary newLibrary = new ShellLibraryClass(); IShellItem folderToSaveInShellItem = Helpers.GetShellItemFromPath(folderToSaveIn); IShellItem savesToShellItem; newLibrary.Save(folderToSaveInShellItem, name, Windows7.DesktopIntegration.Interop.SafeNativeMethods.LIBRARYSAVEFLAGS.LSF_OVERRIDEEXISTING, out savesToShellItem); newLibrary.Commit(); string baseName = System.IO.Path.Combine(folderToSaveIn, name); string fullName = System.IO.Path.ChangeExtension(baseName, ".library-ms"); ShellLibrary shellLibrary = new ShellLibrary(newLibrary, fullName); Marshal.ReleaseComObject(savesToShellItem); return(shellLibrary); }