This topic has not yet been rated - Rate this topic

Environment.GetFolderPath Method (Environment.SpecialFolder)

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
public static string GetFolderPath(
	Environment.SpecialFolder folder
)

Parameters

folder
Type: System.Environment.SpecialFolder

An enumerated constant that identifies a system special folder.

Return Value

Type: System.String
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.
ExceptionCondition
ArgumentException

folder is not a member of System.Environment.SpecialFolder.

PlatformNotSupportedException

The current platform is not supported.

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 the CSIDL values topic.

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
*/

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.