/// <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)); } }
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; } }
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) { } } }