Article C0004 C# .NET
Temporary Files folder

The temporary folder is not part of the ‘Special Folder’ collection which was demonstrated in the C0001 article. So how do you get access to this folder? Using my DOS knowledge I remember the COMSPEC, with their variables which can be listed using a command prompt’s SET command. In most cases two environment variables with regard to the temporary folder can be found: TMP and TEMP.

Using the following command the temporary files folder can be obtained using the computers COMSPEC (environment variables): string temp_path = Environment.GetEnvironmentVariable("TEMP");

If you want the whole list of environment variable into a ListBox add the Collections namespace to your project and use the following code in the desired function:

foreach (DictionaryEntry env_item in Environment.GetEnvironmentVariables())
{
    envVars.Items.Add(env_item.Key+" = "+env_item.Value);
}
Like often, there are more ways to reach your goal. The System.IO namespace includes the Path collection which contains the following function:

string temp_path = Path.GetTempPath();
Or within the namespace added:

string temp+path = System.IO.Path.GetTempPath();
The complete sample project of this article can be downloaded here.

~Edward