Beispiel #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;
            }
        }
Beispiel #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 && item != null)
                {
                    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
            {
                // FAB: 16/03/18
                if (FileSystemPath != "")
                {
                    return(new Uri(FileSystemPath));
                }
                else
                {
                    return(new Uri("shell:///"));
                }
            }
        }