예제 #1
0
        /// <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;
        }
예제 #2
0
        /// <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;
        }
예제 #3
0
 /// <summary>
 /// Load an existing library and create a <see cref="ShellLibrary"/> object that enables 
 /// the management of this library
 /// </summary>
 /// <param name="path">The library to load.</param>
 /// <param name="isWritable">Define the access code to the library</param>
 /// <returns>A <see cref="ShellLibrary"/> object</returns>
 public static ShellLibrary Load(string path, bool isWritable)
 {
     IShellLibrary library = new ShellLibraryClass();
     IShellItem pathShellItem = Helpers.GetShellItemFromPath(path);
     library.LoadLibraryFromItem(pathShellItem, isWritable ? Windows7.DesktopIntegration.Interop.SafeNativeMethods.StorageInstantiationModes.STGM_READWRITE : Windows7.DesktopIntegration.Interop.SafeNativeMethods.StorageInstantiationModes.STGM_READ);
     ShellLibrary shellLibrary = new ShellLibrary(library, path);
     return shellLibrary;
 }
예제 #4
0
 /// <summary>
 /// Load an existing library and create a <see cref="ShellLibrary"/> object that enables 
 /// the management of this library from a known folder location
 /// </summary>
 /// <param name="knownFolderLibrary">The known folder library to load</param>
 /// <param name="isWritable">Define the access code to the library</param>
 /// <returns>A <see cref="ShellLibrary"/> object</returns>
 public static ShellLibrary Load(KnownFolder knownFolderLibrary, bool isWritable)
 {
     IShellLibrary library = new ShellLibraryClass();
     Guid folderId = knownFolderLibrary.FolderId;
     library.LoadLibraryFromKnownFolder(ref folderId, isWritable ? Windows7.DesktopIntegration.Interop.SafeNativeMethods.StorageInstantiationModes.STGM_READWRITE : Windows7.DesktopIntegration.Interop.SafeNativeMethods.StorageInstantiationModes.STGM_READ);
     string fullName = System.IO.Path.ChangeExtension(knownFolderLibrary.Path, ".library-ms");
     ShellLibrary shellLibrary = new ShellLibrary(library, fullName);
     return shellLibrary;
 }