Ejemplo n.º 1
0
        void InitializeFromShellUri(Uri uri)
        {
            KnownFolderManager manager = new KnownFolderManager();
            string             path    = uri.GetComponents(UriComponents.Path, UriFormat.Unescaped);
            string             knownFolder;
            string             restOfPath;
            int separatorIndex = path.IndexOf('/');

            if (separatorIndex != -1)
            {
                knownFolder = path.Substring(0, separatorIndex);
                restOfPath  = path.Substring(separatorIndex + 1);
            }
            else
            {
                knownFolder = path;
                restOfPath  = string.Empty;
            }

            m_ComInterface = manager.GetFolder(knownFolder).CreateShellItem().ComInterface;

            if (restOfPath != string.Empty)
            {
                m_ComInterface = this[restOfPath.Replace('/', '\\')].ComInterface;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a URI representation of the <see cref="ShellItem"/>.
        /// </summary>
        public Uri ToUri()
        {
            KnownFolderManager manager     = new KnownFolderManager();
            StringBuilder      path        = new StringBuilder("shell:///");
            KnownFolder        knownFolder = manager.FindNearestParent(this);

            if (knownFolder != null)
            {
                List <string> folders         = new List <string>();
                ShellItem     knownFolderItem = knownFolder.CreateShellItem();
                ShellItem     item            = this;

                while (item != knownFolderItem)
                {
                    folders.Add(item.GetDisplayName(SIGDN.PARENTRELATIVEPARSING));
                    item = item.Parent;
                }

                folders.Reverse();
                path.Append(knownFolder.Name);
                foreach (string s in folders)
                {
                    path.Append('/');
                    path.Append(s);
                }

                return(new Uri(path.ToString()));
            }
            else
            {
                return(new Uri(FileSystemPath));
            }
        }
Ejemplo n.º 3
0
        public ShellItemBrowseForm()
        {
            InitializeComponent();

            var manager = new KnownFolderManager();

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

                    item.Tag = knownFolder;

                    if (item.Text == Resources.ShellItemBrowseForm_ShellItemBrowseForm_Personal)
                    {
                        item.Text  = Resources.ShellItemBrowseForm_ShellItemBrowseForm_Personal__My_Documents_;
                        item.Group = knownFolderList.Groups["common"];
                    }
                    else if ((item.Text == Resources.ShellItemBrowseForm_ShellItemBrowseForm_Desktop) ||
                             (item.Text == Resources.ShellItemBrowseForm_ShellItemBrowseForm_Downloads) ||
                             (item.Text == Resources.ShellItemBrowseForm_ShellItemBrowseForm_MyComputerFolder))
                    {
                        item.Group = knownFolderList.Groups["common"];
                    }
                    else
                    {
                        item.Group = knownFolderList.Groups["all"];
                    }
                }
                catch (Exception)
                {
                    // ignored
                }
            }
        }
Ejemplo n.º 4
0
        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)
                {
                }
            }
        }