Esempio n. 1
0
        public string GetPath(KnownFolderRetrievalOptions options)
        {
            IntPtr pointerToPath = IntPtr.Zero;
            string path;

            try
            {
                if (Category == KnownFolderCategory.Virtual)
                {
                    return(null);
                }
                else
                {
                    _knownFolder.GetPath(options, out pointerToPath);
                    path = Marshal.PtrToStringUni(pointerToPath);
                }
            }
            catch (System.IO.FileNotFoundException)
            {
                path = null;
            }
            catch (System.IO.DirectoryNotFoundException)
            {
                path = null;
            }
            finally
            {
                Marshal.FreeCoTaskMem(pointerToPath);
            }
            return(path);
        }
        /// <summary>
        ///     パス情報を初期化します。
        /// </summary>
        /// <param name="knownFolderInterface"></param>
        private void InitializePath(IKnownFolder knownFolderInterface)
        {
            Contract.Requires(knownFolderInterface != null);

            this.Path = String.Empty;

            if (this.Category == KnownFolderCategories.Virtual)
            {
                this.PathExists = false;
            }
            else
            {
                try
                {
                    this.Path       = knownFolderInterface.GetPath(0);
                    this.PathExists = true;
                }
                catch (FileNotFoundException)
                {
                    this.PathExists = false;
                }
                catch (DirectoryNotFoundException)
                {
                    this.PathExists = false;
                }
            }
        }
Esempio n. 3
0
        public void KnownFolder_GetPath()
        {
            using (var id = ShellDesktopMethods.GetKnownFolderId(KNOWNFOLDERID.Windows))
            {
                id.IsInvalid.Should().BeFalse();
                ShellDesktopMethods.GetNameFromId(id, SIGDN.PARENTRELATIVE).Should().Be("Windows");

                IKnownFolderManager manager = ShellDesktopMethods.GetKnownFolderManager();
                IKnownFolder        folder  = manager.GetFolder(KNOWNFOLDERID.Windows);
                folder.GetPath(0).Should().Be(ShellDesktopMethods.GetNameFromId(id, SIGDN.FILESYSPATH));
            }
        }
Esempio n. 4
0
        public void KnownFolder_GetPath()
        {
            using (var id = ShellMethods.GetKnownFolderId(KnownFolderIds.Windows))
            {
                id.IsInvalid.Should().BeFalse();
                ShellMethods.GetNameFromId(id, ShellItemDisplayNames.ParentRelative).Should().BeEquivalentTo("Windows");

                IKnownFolderManager manager = ShellMethods.GetKnownFolderManager();
                IKnownFolder        folder  = manager.GetFolder(KnownFolderIds.Windows);
                folder.GetPath(0).Should().BeEquivalentTo(ShellMethods.GetNameFromId(id, ShellItemDisplayNames.FilesysPath));
            }
        }
Esempio n. 5
0
 public string GetPath(KnownFolderRetrievalOptions options)
 {
     IntPtr pointerToPath = IntPtr.Zero;
     string path;
     try
     {
         _knownFolder.GetPath(options, out pointerToPath);
         path = Marshal.PtrToStringUni(pointerToPath);
     }
     finally
     {
         Marshal.FreeCoTaskMem(pointerToPath);
     }
     return path;
 }