//[Fact]
        //public async Task ThisPCDesktopFolderTest()
        //{
        //    await STATask.Run(() =>
        //    {
        //        var actual = ShellKnownFolderFactory.FromCanonicalName("ThisPCDesktopFolder");

        //        Assert.NotNull(actual);
        //        Assert.Equal("ThisPCDesktopFolder", actual.CanonicalName);
        //        Assert.Equal(KnownFolderCategories.Virtual, actual.Category);

        //        Dump(actual);
        //    });
        //}

        private static void Dump(ShellKnownFolder folder)
        {
            Console.WriteLine("CanonicalName={0}", folder.CanonicalName);
            Console.WriteLine("DisplayName={0}", folder.DisplayName);
            Console.WriteLine("ParsingName={0}", folder.ParsingName);
            Console.WriteLine("Category={0}", folder.Category);
            Console.WriteLine("Path={0}", folder.Path);
            Console.WriteLine();
        }
 private void Dump(ShellKnownFolder shellKnownFolder)
 {
     Output.WriteLine($"Name = {shellKnownFolder.Name}");
     Output.WriteLine($"DisplayName = {shellKnownFolder.DisplayName}");
     Output.WriteLine($"ParsingName = {shellKnownFolder.ParsingName}");
     if (shellKnownFolder.Parent != null)
     {
         Output.WriteLine($"Parent Type = {shellKnownFolder.Parent.GetType()}");
         Output.WriteLine($"Parent = {shellKnownFolder.Parent}");
     }
     Output.WriteLine("----");
 }
Exemple #3
0
        /// <summary>
        ///     Create new shell library.
        /// </summary>
        /// <param name="libraryName">Name of the library to be created.</param>
        /// <param name="sourceKnownFolder">Known folder of library.</param>
        /// <param name="overwrite">A value indicating whether to overwrite an existing library.</param>
        /// <returns>Created <see cref="ShellLibrary" />.</returns>
        public static ShellLibrary Create(string libraryName, ShellKnownFolder sourceKnownFolder, bool overwrite)
        {
            Contract.Requires <ArgumentException>(!String.IsNullOrWhiteSpace(libraryName));
            Contract.Requires <ArgumentNullException>(sourceKnownFolder != null);
            Contract.Ensures(Contract.Result <ShellLibrary>() != null);

            var shellLibraryInterface = CreateShellLibraryNativeInterface();

            var         guid  = sourceKnownFolder.FolderId;
            var         flags = GetLibrarySaveOptions(overwrite);
            IShellItem2 shellItem2;

            shellLibraryInterface.SaveInKnownFolder(ref guid, libraryName, flags, out shellItem2);

            return(new ShellLibrary(new ShellItem(shellItem2), shellLibraryInterface, libraryName));
        }
Exemple #4
0
        /// <summary>
        ///     Create a new instance of the <see cref="ShellLibrary" /> class
        ///     to the specified known folder.
        /// </summary>
        /// <param name="sourceKnownFolder">Shell known folder.</param>
        /// <param name="isReadOnly">A value that indicates whether the library is readonly.</param>
        /// <returns>Created <see cref="ShellLibrary" />.</returns>
        public static ShellLibrary Load(ShellKnownFolder sourceKnownFolder, bool isReadOnly = true)
        {
            Contract.Requires <ArgumentNullException>(sourceKnownFolder != null);
            Contract.Ensures(Contract.Result <ShellLibrary>() != null);

            var shellItem             = sourceKnownFolder.ShellItem.ShellItemInterface;
            var shellLibraryInterface = CreateShellLibraryNativeInterface();

            try
            {
                var guid  = sourceKnownFolder.FolderId;
                var flags = isReadOnly ? STGM.STGM_READ : STGM.STGM_READWRITE;
                shellLibraryInterface.LoadLibraryFromKnownFolder(ref guid, flags);
            }
            catch (Exception ex)
            {
                throw new ArgumentException(ErrorMessages.ShellLibraryInvalidLibrary, ex);
            }

            var libraryShellItem = new ShellItem(shellItem);
            var libraryName      = libraryShellItem.GetDisplayName();

            return(new ShellLibrary(libraryShellItem, shellLibraryInterface, libraryName));
        }