Identifying System Folders
The Microsoft Windows environment includes many special folders, such as the folders for the desktop, music and pictures as well as the program files and system directories. These folders do not have fixed paths so they must be accessed correctly.
The Environment class is a standard class within the System namespace. It provides information relating to the current Windows environment. The Environment class contains a static method named GetFolderPath that allows you to determine the location of one of many special folders.
The GetFolderPath method requires a single parameter that identifies the system folder to be found. This parameter uses the SpecialFolder enumeration, which contains the list of directories that may be identified. For example, the following code displays the path to the user's "desktop" folder.
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
The SpecialFolder enumeration contains constants for many useful system folders. The following table lists the constants and describes their usage with the GetFolderPath method.
|ApplicationData||Returns the folder that contains the application-specific data that is held in the user's roaming profile. This information is transferred to a network server and moved between machines when roaming profiles are in use.|
|CommonApplicationData||Returns the folder that contains application-specific data that is shared by all users of the computer.|
|CommonProgramFiles||Returns the folder that is used for common program components that are shared by multiple applications.|
|Cookies||Returns the folder that holds web browser cookies.|
|Desktop||Returns the logical folder location of the desktop.|
|DesktopDirectory||Returns the physical folder location of the desktop.|
|Favorites||Returns that folder that contains the user's favourite items, including web site bookmarks.|
|History||Returns the folder that holds the user's Internet browsing history.|
|InternetCache||Returns the folder that contains the user's temporary Internet files.|
|LocalApplicationData||Returns the folder that contains application-specific data that is held in the user's local profile. This information is not included in the roaming profile.|
|MyComputer||Returns the location of the "My Computer" folder. This is always an empty string as there is no physical location for My "Computer".|
|MyMusic||Returns the location of the user's "My Music" folder.|
|MyPictures||Returns the location of the user's "My Computer" folder.|
|Personal||Returns the user's personal document folder. This is generally the same as the "My Documents" folder.|
|ProgramFiles||Returns the standard location for installed program files.|
|Programs||Returns the path to the Programs folder of the user's Start menu.|
|MyDocuments||Only available in .NET framework 2.0 and later, this returns the location of the user's "My Documents" directory.|
|Recent||Returns the folder that contains shortcuts to the user's recently opened files.|
|SendTo||Returns the folder that contains items for the "Send To" menu.|
|StartMenu||Returns the folder that contains the user's Start Menu items.|
|Startup||Returns the folder containing shortcuts to programs that are launched automatically at start-up.|
|System||Returns the folder that contains the Microsoft Windows system files.|
|Templates||Returns the folder to be used to hold standard document templates.|
16 February 2008