BlackWaspTM

This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

System Information
.NET 4.0+

Identifying .NET 4.0 Special Folders

The Microsoft Windows environment includes many special folders, the paths of which can be identified using the Environment.GetFolderPath method. The number of such folders has doubled since the release of the .NET framwork version 1.1.

Environment Class

In an earlier article I described how you can identify the system folders for the currently logged-in user in order to find their locations. This allows you to find, for example, the user's default folder for application data. You can then store information in this folder, or in a subfolder, making the information part of the user's roaming profile. The previous article described the special folders that were available when using version 1.1 of the .NET framework. Since then, the number of available system folders has more than doubled. This article describes the new directories that can be located when using the .NET framework version 4.0.

The manner for accessing the paths of system folders is unchanged. As before, you call the Environment class' GetFolderPath method, passing a value from the Environment.SpecialFolder enumeration to determine which path to obtain. The results are returned in a string. The new paths are accessed by using extra constant values in the enumeration.

New Enumeration Constants

The list of new constants is shown in the table below, which includes the name of the constant and the result of using it with the GetFolderPath method:

ConstantDescription
AdminToolsReturns the folder that holds administrative tools, including Microsoft Management Console (MMC) consoles that have been modified by the user. This folder is part of the user's roaming profile.
CDBurningReturns the path of the folder used to temporarily hold files whilst they are waiting to be written to a CD or DVD.
CommonAdminToolsReturns the folder that holds administrative tools that are shared by all users of the computer.
CommonDocumentsReturns the path to the shared documents folder that is accessible by all users.
CommonMusicReturns the path to the shared music folder that is accessible by all users.
CommonOemLinksThis constant is available for backwards compatibility. It returns an empty string.
CommonPicturesReturns the path to the shared images folder that is accessible by all users.
CommonStartMenuReturns the path to the shared Start menu folder that is accessible by all users. Items in this folder appear in the Start menu no matter which user is logged on to Microsoft Windows.
CommonProgramFilesX86Returns the path to the folder that contains 32-bit program files and components that are shared between programs and are available to all users of the computer.
CommonProgramsReturns the path to the folder that contains program files and components that are shared between programs and are available to all users of the computer.
CommonStartupReturns the path to the Startup folder that is accessible by all users. Shortcuts added to the folder are launched automatically at the end of the logon process.
CommonDesktopDirectoryReturns the path to the shared Desktop folder that is accessible by all users. Items in this folder appear on the desktop.
CommonTemplatesReturns the path to the shared templates folder that is shared by all users. This folder is not present for operating systems prior to Windows NT.
CommonVideosReturns the path to the shared videos folder that is accessible by all users.
FontsReturns the folder that contains the list of fonts installed on the computer.
LocalizedResourcesReturns the folder that contains resources that are localised for the current user.
MyDocumentsIntroduced in .NET 2.0, this special folder returns the path to the current user's documents folder. This value is equivalent to the "Personal" constant, sharing the same integer value.
MyVideosReturns the path to the current user's videos folder.
NetworkShortcutsReturns the path of the My Network Shortcuts virtual folder, which can contain links to networked resources, such as remote folders and FTP sites.
PrinterShortcutsReturns the path of the Printer Shortcuts folder. This can contain links that appear in the Printers virtual folder.
ProgramFilesX86Returns the path to the Program Files folder that contains the user's 32-bit software.
ResourcesReturns the folder that contains resources that can be used by the current user.
SystemX86Returns the path of the Windows System folder.
UserProfileReturns the root folder of the current user's profile. This folder should not be used to store files. Instead, use the path from the ApplicationData special folder.
WindowsReturns the path of the Windows folder.

Displaying all Special Folders

The following code loops through a sorted list of special folders, including those covered in the earlier article, outputting the name of the SpecialFolder constant and its current path:

var folders = Enum.GetValues(typeof(Environment.SpecialFolder))
    .OfType<Environment.SpecialFolder>().OrderBy(f=>f.ToString());
int maxLength = folders.Max(f=>f.ToString().Length);

foreach (var folder in folders)
{
    Console.WriteLine("{0} - {1}", folder.ToString().PadRight(maxLength),
        Environment.GetFolderPath(folder));
}
24 March 2012