Bewerken

Share via


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 System::String ^ GetFolderPath(Environment::SpecialFolder folder);
public static string GetFolderPath (Environment.SpecialFolder folder);
static member GetFolderPath : Environment.SpecialFolder -> string
Public Shared Function GetFolderPath (folder As Environment.SpecialFolder) As String

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 namespace System;
int main()
{
   Console::WriteLine();
   Console::WriteLine( "GetFolderPath: {0}", Environment::GetFolderPath( Environment::SpecialFolder::System ) );
}

/*
This example produces the following results:

GetFolderPath: C:\WINNT\System32
*/
// 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
*/
// Sample for the Environment.GetFolderPath method
open System

printfn $"\nGetFolderPath: {Environment.GetFolderPath Environment.SpecialFolder.System}"
            
// This example produces the following results:
//     GetFolderPath: C:\WINNT\System32
' Sample for the Environment.GetFolderPath method
Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      Console.WriteLine("GetFolderPath: {0}", Environment.GetFolderPath(Environment.SpecialFolder.System))
   End Sub
End Class
'
'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

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 System::String ^ GetFolderPath(Environment::SpecialFolder folder, Environment::SpecialFolderOption option);
public static string GetFolderPath (Environment.SpecialFolder folder, Environment.SpecialFolderOption option);
static member GetFolderPath : Environment.SpecialFolder * Environment.SpecialFolderOption -> string
Public Shared Function GetFolderPath (folder As Environment.SpecialFolder, option As Environment.SpecialFolderOption) As String

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