Beispiel #1
0
        public void KnownFolderManager_implements_IKnownFolderManager()
        {
            KnownFolderManager  obj = new KnownFolderManager();
            IKnownFolderManager knownFolderManager = (IKnownFolderManager)obj;

            Assert.IsNotNull(knownFolderManager);
        }
Beispiel #2
0
        /// <summary>
        ///     Create a new instance of the <see cref="ShellKnownFolder" /> class
        ///     to the specified known folder GUID.
        /// </summary>
        /// <param name="knownFolderId">Known folder GUID.</param>
        /// <returns><see cref="ShellKnownFolder" />.</returns>
        internal static ShellKnownFolder FromKnownFolderIdInternal(Guid knownFolderId)
        {
            IKnownFolder        knownFolderNative;
            IKnownFolderManager knownFolderManager = new KnownFolderManager();
            var hr = knownFolderManager.GetFolder(knownFolderId, out knownFolderNative);

            if (HRESULT.Failed(hr))
            {
                return(null);
            }
            return(CreateKnownFolder(knownFolderNative));
        }
Beispiel #3
0
        /// <summary>
        ///     Create a new instance of the <see cref="IKnownFolder" /> instance
        ///     to the specified PIDL.
        /// </summary>
        /// <param name="pidl">PIDL.</param>
        /// <returns><see cref="IKnownFolder" />.</returns>
        internal static IKnownFolder FromPIDL(PIDL pidl)
        {
            IKnownFolder        knownFolder;
            IKnownFolderManager knownFolderManager = new KnownFolderManager();
            var hr = knownFolderManager.FindFolderFromIDList(pidl, out knownFolder);

            if (HRESULT.Failed(hr))
            {
                return(null);
            }
            return(knownFolder);
        }
Beispiel #4
0
        /// <summary>
        ///     Create a new instance of the <see cref="ShellKnownFolder" /> class
        ///     to the specified canonical name.
        /// </summary>
        /// <param name="canonicalName">Canonical name of known folder.</param>
        /// <returns><see cref="ShellKnownFolder" />.</returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="canonicalName" /> is <c>null</c>.
        /// </exception>
        /// <exception cref="ArgumentException">
        ///     <para>
        ///         <paramref name="canonicalName" /> is empty string.
        ///     </para>
        ///     or
        ///     <para>
        ///         There is no standard folder matching <paramref name="canonicalName" />.
        ///     </para>
        /// </exception>
        public static ShellKnownFolder FromCanonicalName(string canonicalName)
        {
            Contract.Requires <ArgumentException>(!String.IsNullOrWhiteSpace(canonicalName));
            Contract.Ensures(Contract.Result <ShellKnownFolder>() != null);

            IKnownFolder knownFolderInterface;
            var          knownFolderManager = new KnownFolderManager();

            knownFolderManager.GetFolderByName(canonicalName, out knownFolderInterface);

            var result = CreateKnownFolder(knownFolderInterface);

            if (result == null)
            {
                throw new ArgumentException(ErrorMessages.ShellInvalidCanonicalName, nameof(canonicalName));
            }
            return(result);
        }
Beispiel #5
0
        /// <summary>
        ///     Create a new instance of the <see cref="ShellKnownFolder" /> class
        ///     to the specified known folder ID.
        /// </summary>
        /// <param name="knownFolderId">Known folder GUID.</param>
        /// <returns>
        ///     <see cref="ShellKnownFolder" />
        /// </returns>
        /// <exception cref="ArgumentException">A known folder matching the specified GUID could not be created.</exception>
        public static ShellKnownFolder FromKnownFolderId(Guid knownFolderId)
        {
            Contract.Ensures(Contract.Result <ShellKnownFolder>() != null);

            IKnownFolder knownFolderNative;
            var          knownFolderManager = new KnownFolderManager();
            var          hr = knownFolderManager.GetFolder(knownFolderId, out knownFolderNative);

            if (HRESULT.Failed(hr))
            {
                throw ShellException.FromHRESULT(hr);
            }

            var result = CreateKnownFolder(knownFolderNative);

            if (result == null)
            {
                throw new ArgumentException(ErrorMessages.KnownFolderInvalidGuid, nameof(knownFolderId));
            }
            return(result);
        }
Beispiel #6
0
        /// <summary>
        ///     Get all the standard folders.
        /// </summary>
        /// <returns>Known folder collection.</returns>
        public static IReadOnlyList <ShellKnownFolder> GetAllFolders()
        {
            Contract.Ensures(Contract.Result <IReadOnlyList <ShellKnownFolder> >() != null);

            var result = new List <ShellKnownFolder>();

            var folders = IntPtr.Zero;

            try
            {
                uint count;
                var  knownFolderManager = new KnownFolderManager();
                knownFolderManager.GetFolderIds(out folders, out count);

                if (count > 0 && folders != IntPtr.Zero)
                {
                    for (var index = 0; index < count; ++index)
                    {
                        var current = new IntPtr(folders.ToInt64() + (Marshal.SizeOf(typeof(Guid)) * index));

                        var knownFolderId = (Guid)Marshal.PtrToStructure(current, typeof(Guid));
                        var knownFolder   = FromKnownFolderIdInternal(knownFolderId);
                        if (knownFolder != null)
                        {
                            result.Add(knownFolder);
                        }
                    }
                }
            }
            finally
            {
                if (folders != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(folders);
                }
            }

            return(result);
        }
        public ShellItemBrowseForm()
        {
            InitializeComponent();

            KnownFolderManager manager = new KnownFolderManager();

            SystemImageList.UseSystemImageList(knownFolderList);
            foreach (KnownFolder knownFolder in manager)
            {
                try
                {
                    ShellItem shellItem = knownFolder.CreateShellItem();
                    ListViewItem item = knownFolderList.Items.Add(knownFolder.Name,
                        shellItem.GetSystemImageListIndex(ShellIconType.LargeIcon, 0));

                    item.Tag = knownFolder;

                    if (item.Text == "Personal")
                    {
                        item.Text = "Personal (My Documents)";
                        item.Group = knownFolderList.Groups["common"];
                    }
                    else if ((item.Text == "Desktop") ||
                               (item.Text == "Downloads") ||
                               (item.Text == "MyComputerFolder"))
                    {
                        item.Group = knownFolderList.Groups["common"];
                    }
                    else
                    {
                        item.Group = knownFolderList.Groups["all"];
                    }
                }
                catch (Exception)
                {
                }
            }
        }
 public void KnownFolderManager_implements_IKnownFolderManager()
 {
     KnownFolderManager obj = new KnownFolderManager();
     IKnownFolderManager knownFolderManager = (IKnownFolderManager)obj;
     Assert.IsNotNull(knownFolderManager);
 }
 public void Can_create_KnownFolderManager()
 {
     KnownFolderManager obj = new KnownFolderManager();
     Assert.IsNotNull(obj);
 }
Beispiel #10
0
        public void Can_create_KnownFolderManager()
        {
            KnownFolderManager obj = new KnownFolderManager();

            Assert.IsNotNull(obj);
        }