Environment.GetFolderPath Method

Definition

Gets the path to the system special folder that is identified by the specified enumeration.

Overloads

GetFolderPath(Environment+SpecialFolder)

Gets the path to the specified system special folder.

GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption)

Gets the path to the specified system special folder using a specified option for accessing special folders.

GetFolderPath(Environment+SpecialFolder)

Source:
Environment.cs
Source:
Environment.cs
Source:
Environment.cs

Gets the path to the specified system special folder.

public static string GetFolderPath (Environment.SpecialFolder folder);

Parameters

folder
Environment.SpecialFolder

One of the enumeration values that identifies a system special folder.

Returns

The path to the specified system special folder, if that folder physically exists on your computer; otherwise, an empty string ("").

A folder will not physically exist if the operating system did not create it, the existing folder was deleted, or the folder is a virtual directory, such as My Computer, which does not correspond to a physical path.

Exceptions

folder is not a member of Environment.SpecialFolder.

The current platform is not supported.

Examples

The following example demonstrates how to use the GetFolderPath method to return and display the path associated with the folder parameter.

// Sample for the Environment.GetFolderPath method
using System;

class Sample
{
    public static void Main()
    {
    Console.WriteLine();
    Console.WriteLine("GetFolderPath: {0}",
                 Environment.GetFolderPath(Environment.SpecialFolder.System));
    }
}
/*
This example produces the following results:

GetFolderPath: C:\WINNT\System32
*/

Remarks

This method retrieves the path to a system special folder, such as Program Files, Programs, System, or Startup, which can be used to access common information. Special folders are set by default by the system, or explicitly by the user, when installing a version of Windows.

The folder parameter designates the special folder to retrieve and must be one of the values in the Environment.SpecialFolder enumeration; any other value throws an exception.

For more information about special folders, see Constant special item ID list (CSIDL).

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption)

Source:
Environment.cs
Source:
Environment.cs
Source:
Environment.cs

Gets the path to the specified system special folder using a specified option for accessing special folders.

public static string GetFolderPath (Environment.SpecialFolder folder, Environment.SpecialFolderOption option);

Parameters

folder
Environment.SpecialFolder

One of the enumeration values that identifies a system special folder.

option
Environment.SpecialFolderOption

One of the enumeration values that specifies options to use for accessing a special folder.

Returns

The path to the specified system special folder, if that folder physically exists on your computer; otherwise, an empty string ("").

A folder will not physically exist if the operating system did not create it, the existing folder was deleted, or the folder is a virtual directory, such as My Computer, which does not correspond to a physical path.

Exceptions

folder is not a member of Environment.SpecialFolder.

-or-

option is not a member of Environment.SpecialFolderOption.

The current platform is not supported.

Remarks

This method retrieves the path to a system special folder, such as Program Files, Programs, System, or Startup, which can be used to access common information. Special folders are set by default by the system, or explicitly by the user, when installing a version of Windows.

The folder parameter designates the special folder to retrieve and must be one of the values in the Environment.SpecialFolder enumeration; any other value throws an exception.

For more information about special folders, see Constant special item ID list (CSIDL).

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1