List the locations of special folders in C#

[special folders]

The System.Environment class’s SpecialFolders enumeration lists special folders such as System, Cookies, Desktop, and so forth. The class’s GetFolderPath method returns the full path for one of the special folders values.

This program uses the following code to enumerate the Environment.SpecialFolders values and call the DescribeFolder method for each of them.

// List the folder types.
private void Form1_Load(object sender, EventArgs e)
    foreach (Environment.SpecialFolder folder_type
        in Enum.GetValues(typeof(Environment.SpecialFolder)))
    txtFolders.Select(0, 0);

The following code shows the DescribeFolder method.

// Add a folder's information to the txtFolders TextBox.
private void DescribeFolder(Environment.SpecialFolder folder_type)
        String.Format("{0,-25}", folder_type.ToString()) +
        Environment.GetFolderPath(folder_type) + "\r\n");

The DescribeFolder method adds text to the txtFolders TextBox. It uses String.Format to display the folder type converted into a string and padded on the right to 25 spaces. It uses the Environment.GetFolderPath method to add the folder’s path to the text and finishes the folder’s entry with a new line.

Download Example   Follow me on Twitter   RSS feed   Donate

This entry was posted in directories, files, system and tagged , , , , , , , , , , , . Bookmark the permalink.

2 Responses to List the locations of special folders in C#

  1. Annon says:

    Download link is broken.

  2. Rod Stephens says:

    Sorry about that. I’ve fixed it. Thanks for pointing this out.

Comments are closed.