Export (0) Print
Expand All

Environment.GetFolderPath Method

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

[Visual Basic]
Public Shared Function GetFolderPath( _
   ByVal folder As Environment.SpecialFolder _
) As String
[C#]
public static string GetFolderPath(
 Environment.SpecialFolder folder
);
[C++]
public: static String* GetFolderPath(
 Environment.SpecialFolder folder
);
[JScript]
public static function GetFolderPath(
   folder : Environment.SpecialFolder
) : String;

Parameters

folder
An enumerated constant that identifies a system special folder.

Return Value

The path to the specified system special folder, if that folder physically exists on your computer; otherwise, the 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

Exception Type Condition
ArgumentException folder is not a member of System.Environment.SpecialFolder.

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 the CSIDL Values topic at http://msdn.microsoft.com/library/en-us/shellcc/platform/Shell/reference/enums/csidl.asp.

Example

[Visual Basic] 
' Sample for the Environment.GetFolderPath method
Imports System

Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      Console.WriteLine("GetFolderPath: {0}", Environment.GetFolderPath(Environment.SpecialFolder.System))
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'GetFolderPath: C:\WINNT\System32
'

[C#] 
// 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
*/

[C++] 
// Sample for the Environment::GetFolderPath method
#using <mscorlib.dll>

using namespace System;

int main() {
   Console::WriteLine();
   Console::WriteLine(S"GetFolderPath: {0}",
      Environment::GetFolderPath(Environment::SpecialFolder::System));
}
/*
This example produces the following results:

GetFolderPath: C:\WINNT\System32
*/

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

Environment Class | Environment Members | System Namespace

Show:
© 2014 Microsoft