Exemplo n.º 1
0
        private static void GetFolder()
        {
            Console.WriteLine("===============GET================");
            IKnownFolderNative f;

            m.GetFolder(_guid, out f);
            if (f != null)
            {
                KnownFoldersSafeNativeMethods.NativeFolderDefinition d2;
                f.GetFolderDefinition(out d2);

                Console.WriteLine("Extension found: {0}, {1}", Marshal.PtrToStringAuto(d2.name), Marshal.PtrToStringAuto(d2.relativePath));
                Console.WriteLine("Extension: ::{{{0}}}\\::{{{1}}}", d2.parentId, f.GetId());

                //Guid ishellItem = new Guid(ShellIIDGuid.IShellItem2);
                //IShellItem2 s;
                //f.GetShellItem((int)(KNOWN_FOLDER_FLAG.KF_FLAG_CREATE
                //    | KNOWN_FOLDER_FLAG.KF_FLAG_DEFAULT_PATH
                //    | KNOWN_FOLDER_FLAG.KF_FLAG_INIT
                //    | KNOWN_FOLDER_FLAG.KF_FLAG_SIMPLE_IDLIST), ref ishellItem, out s);
            }
            else
            {
                Console.WriteLine("Got nothing");
            }
            Console.WriteLine();
            Console.WriteLine();
        }
Exemplo n.º 2
0
		/// <summary>
		/// Returns a known folder given a globally unique identifier.
		/// </summary>
		/// <param name="knownFolderId">A GUID for the requested known folder.</param>
		/// <returns>A known folder representing the specified name.</returns>
		/// <exception cref="System.ArgumentException">Thrown if the given Known Folder ID is invalid.</exception>
		public static IKnownFolder FromKnownFolderId(Guid knownFolderId) {
			IKnownFolderNative knownFolderNative;
			KnownFolderManagerClass knownFolderManager = new KnownFolderManagerClass();

			HResult hr = knownFolderManager.GetFolder(knownFolderId, out knownFolderNative);
			if (hr != HResult.Ok) { throw new ShellException(hr); }

			IKnownFolder kf = GetKnownFolder(knownFolderNative);
			if (kf == null) {
				throw new ArgumentException(LocalizedMessages.KnownFolderInvalidGuid, "knownFolderId");
			}
			return kf;
		}
        /// <summary>
        /// Returns a known folder given a globally unique identifier.
        /// </summary>
        /// <param name="knownFolderId">A GUID for the requested known folder.</param>
        /// <returns>A known folder representing the specified name.</returns>
        /// <exception cref="System.ArgumentException">Thrown if the given Known Folder ID is invalid.</exception>
        public static IKnownFolder FromKnownFolderId(Guid knownFolderId)
        {
            IKnownFolderNative      knownFolderNative;
            KnownFolderManagerClass knownFolderManager = new KnownFolderManagerClass();

            HResult hr = knownFolderManager.GetFolder(knownFolderId, out knownFolderNative);

            if (hr != HResult.S_OK)
            {
                throw new Exception(hr.ToString());
            }

            IKnownFolder kf = GetKnownFolder(knownFolderNative);

            if (kf == null)
            {
                throw new ArgumentException("Invalid GUID", "knownFolderId");
            }
            return(kf);
        }