The Shell Namespace

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

The Shell Namespace

This is a short introduction to the Windows shell name space which may be of interest for advanced users.

The Windows shell uses a single hierarchical name space to organize all objects such as files, storage devices, printers, network resources and anything else that can be viewed using the Explorer. The root of this unified name space is the Windows desktop. While similar to a file system's directory structure, the name space contains more types of objects then just files and directories.

Shell Folders

Windows uses a data structure that represents the hierarchy of objects all the way from the desktop to every item that can be seen in the Explorer. From the desktop you can get to drives, Control Panel, Printers and Dial-UP Networking. Look at the left pane of the Explorer to see the hierarchy of objects clearly. These items are called virtual folders, virtual because they refer to items in the name space that can contain other name space items, as opposed to groups of files. An application can use shell functions to retrieve the locations of these special folders.

Because there are many kinds of folders and file objects, each folder is an OLE component object model (COM) object that can enumerate its contents and carry out other actions. More precisely, each folder implements the IShellFolder interface. Retrieving the IShellFolder interface for a shell folder is referred to as binding to the folder.

Item Identifiers / PIDLs

Objects in the shell namespace are represented by item identifiers and item identifier lists. An item identifier uniquely identifies an item within its parent folder. An item identifier list uniquely identifies an item within the shell namespace by tracing a path to the item from a known point - usually the desktop. A pointer to an item identifier list (PIDL) is used throughout the shell to identify an item.

Item identifiers (often referenced as PIDLs) are much like the file names and paths, respectively, used in a file system. However, they share this important difference: item identifiers are binary data structures that never appear to the user. However there are functions to retrieve display names from an Item Identifier or an Item Identifier List that may be presented to the user.

Besides ShellFolders and ItemIdLists there are many other interfaces, that Windows provides to connect and interact with the Windows Shell.

In depth information can be found on Microsoft docs, e.g. Introduction to the Shell Namespace.

 

ShellBrowser components

ShellBrowser makes use of many of these Windows Shell interfaces. Most of it goes on under the hood inside the components, without the need having to deal with the respective APIs explicitly.

You might have use-cases though where instead of using normal system file paths, you will want to work with the PIDL type of item identifier instead.

ItemIdLists in ShellBrowser.NET

ShellBrowser.NET hosts an Item Identifier via the class ItemIdList. The class not only handles the PIDLs but comprises other shell interfaces needed for additional functionality.

The ItemIdList class is used by all components in ShellBrowser.NET. Most of them accept paths both as a normal File System Path as string, as well as ItemIdList.

Example:

Using ShellListView.Path, you can set the folder that should be displayed. You can achieve the same using

 lShellListView.FolderIdList = new ItemIdList(path)

The advantage of the ItemIdList is that it also supports virtual elements that do not have a physical path:

 lShellListView.FolderIdList = ItemIdList.GetForSpecialFolder(ShellFolder.AllTasks);

 

But you can also use the ItemIdList "standalone", e.g. to  retrieve file information.

Example:

The following line gets the artist stored in some mp3 file:

string artist = new ItemIdList(mp3FilePath).GetPropertyDisplayValue(SHCOLUMNID.ShellColumnMusicArtist);

It's also possible to set values. The following example sets the artist for the selected items in a ShellListView. It also shows another example of the usage of ItemIdList in the ShellBrowser control - list items, tree nodes etc. usually have a property "AbsoluteItemIdList" that contains the fully qualified Identifier list of the respective element.

 

foreach (ShellListItem lItem in shellListView1.SelectedItems)

{

  lItem.AbsoluteItemIdList.SetPropertyValue(SHCOLUMNID.ShellColumnMusicArtist, "Nirvana");

}

 

For more information on the ItemIdList class please see the API-documentation of ShellBrowser.NET.