packages/Windows API Code Pack 1.1/source/WindowsAPICodePack/Shell/Common/ShellLibrary.cs
/// <summary>
/// Load the library using a number of options
/// </summary>
/// <param name="libraryName">The name of the library.</param>
/// <param name="folderPath">The path to the library.</param>
/// <param name="isReadOnly">If <B>true</B>, opens the library in read-only mode.</param>
/// <returns>A ShellLibrary Object</returns>
Load the library using a number of options
Load the library using a number of options
public static ShellLibrary Load(string libraryName, string folderPath, bool isReadOnly)
        {
            CoreHelpers.ThrowIfNotWin7();
            string shellItemPath = System.IO.Path.Combine(folderPath, libraryName + FileExtension);
            ShellFile item = ShellFile.FromFilePath(shellItemPath);
            IShellItem nativeShellItem = item.NativeShellItem;
            INativeShellLibrary nativeShellLibrary = (INativeShellLibrary)new ShellLibraryCoClass();
            AccessModes flags = isReadOnly ?
                    AccessModes.Read :
                    AccessModes.ReadWrite;
            nativeShellLibrary.LoadLibraryFromItem(nativeShellItem, flags);
            ShellLibrary library = new ShellLibrary(nativeShellLibrary);
            try
            {
                library.nativeShellItem = (IShellItem2)nativeShellItem;
                library.Name = libraryName;
                return library;
            }
            catch
            {
                library.Dispose();
                throw;
            }
        }
public static ShellLibrary Load ( string libraryName , string folderPath , bool isReadOnly ) { CoreHelpers . ThrowIfNotWin7 ( ) ; string shellItemPath = System . IO . Path . Combine ( folderPath , libraryName + FileExtension ) ; ShellFile item = ShellFile . FromFilePath ( shellItemPath ) ; IShellItem nativeShellItem = item . NativeShellItem ; INativeShellLibrary nativeShellLibrary = ( INativeShellLibrary ) new ShellLibraryCoClass ( ) ; AccessModes flags = isReadOnly ? AccessModes . Read : AccessModes . ReadWrite ; nativeShellLibrary . LoadLibraryFromItem ( nativeShellItem , flags ) ; ShellLibrary library = new ShellLibrary ( nativeShellLibrary ) ; try { library . nativeShellItem = ( IShellItem2 ) nativeShellItem ; library . Name = libraryName ; return library ; } catch { library . Dispose ( ) ; throw ; } }
Load the library using a number of options
Load the library using a number of options
// Create the shell item path
A ShellLibrary Object
A ShellLibrary Object
libraryName
string
The name of the library.
The name of the library .
folderPath
string
The path to the library.
The path to the library .
isReadOnly
bool
None