Beispiel #1
0
        /// <summary>
        /// Creates a shell library in the Libraries Known Folder,
        /// using the given IKnownFolder
        /// </summary>
        /// <param name="sourceKnownFolder">KnownFolder from which to create the new Shell Library</param>
        /// <param name="isReadOnly">If <B>true</B> , opens the library in read-only mode.</param>
        private ShellLibrary(IKnownFolder sourceKnownFolder, bool isReadOnly)
            : this()
        {
            Debug.Assert(sourceKnownFolder != null);

            // Keep a reference locally
            knownFolder = sourceKnownFolder;

            nativeShellLibrary = (INativeShellLibrary) new ShellLibraryCoClass();

            AccessModes flags = isReadOnly ?
                                AccessModes.Read :
                                AccessModes.ReadWrite;

            // Get the IShellItem2
            base.nativeShellItem = ((ShellObject)sourceKnownFolder).NativeShellItem2;

            Guid guid = sourceKnownFolder.FolderId;

            // Load the library from the IShellItem2
            try {
                nativeShellLibrary.LoadLibraryFromKnownFolder(ref guid, flags);
            } catch (InvalidCastException) {
                throw new ArgumentException(LocalizedMessages.ShellLibraryInvalidLibrary, "sourceKnownFolder");
            } catch (NotImplementedException) {
                throw new ArgumentException(LocalizedMessages.ShellLibraryInvalidLibrary, "sourceKnownFolder");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates a shell library in the Libraries Known Folder,
        /// using the given IKnownFolder
        /// </summary>
        /// <param name="sourceKnownFolder">KnownFolder from which to create the new Shell Library</param>
        /// <param name="isReadOnly">If <B>true</B> , opens the library in read-only mode.</param>
        private ShellLibrary(IKnownFolder sourceKnownFolder, bool isReadOnly)
        {
            CoreHelpers.ThrowIfNotWin7();

            Debug.Assert(sourceKnownFolder != null);

            // Keep a reference locally
            knownFolder = sourceKnownFolder;

            nativeShellLibrary = (INativeShellLibrary) new ShellLibraryCoClass();

            ShellNativeMethods.STGM flags =
                isReadOnly ?
                ShellNativeMethods.STGM.Read :
                ShellNativeMethods.STGM.ReadWrite;

            // Get the IShellItem2
            base.nativeShellItem = ((ShellObject)sourceKnownFolder).NativeShellItem2;

            Guid guid = sourceKnownFolder.FolderId;

            // Load the library from the IShellItem2
            try
            {
                nativeShellLibrary.LoadLibraryFromKnownFolder(ref guid, flags);
            }
            catch (InvalidCastException)
            {
                throw new ArgumentException("The given known folder is not a valid library.", "sourceKnownFolder");
            }
            catch (NotImplementedException)
            {
                throw new ArgumentException("The given known folder is not a valid library.", "sourceKnownFolder");
            }
        }