This documentation is archived and is not being maintained.

Environment.CurrentDirectory Property

Gets and sets the fully qualified path of the current directory; that is, the directory from which this process starts.

[Visual Basic]
Public Shared Property CurrentDirectory As String
public static string CurrentDirectory {get; set;}
public: __property static String* get_CurrentDirectory();
public: __property static void set_CurrentDirectory(String*);
public static function get CurrentDirectory() : String;
public static function set CurrentDirectory(String);

Property Value

A string containing a directory path.


Exception Type Condition
ArgumentException Attempted to set to an empty string ("").
ArgumentNullException Attempted to set to a null reference (Nothing in Visual Basic).
IOException An I/O error occurred.
FileNotFoundException Attempted to set a local path that cannot be found.
DirectoryNotFoundException Attempted to set a universal naming convention (UNC) path that cannot be found.
SecurityException The caller does not have the appropriate permission.


By definition, if this process starts in the root directory of a local or network drive, the value of this property is the drive name followed by a trailing slash (for example, "C:\"). If this process starts in a subdirectory, the value of this property is the drive and subdirectory path, without a trailing slash (for example, "C:\mySubDirectory").


[Visual Basic, C#, C++] The following code example demonstrates setting the CurrentDirectory property.

[Visual Basic] 
' Change the directory to %WINDIR%                            
Environment.CurrentDirectory = Environment.GetEnvironmentVariable("windir")
Dim info As New DirectoryInfo(".")
Console.WriteLine(("Directory Info:   " + info.FullName))        

// Change the directory to %WINDIR%                            
Environment.CurrentDirectory = Environment.GetEnvironmentVariable("windir");        
DirectoryInfo info = new DirectoryInfo(".");
    Console.WriteLine("Directory Info:   "+info.FullName);

// Change the directory to %WINDIR%                            
Environment::CurrentDirectory = Environment::GetEnvironmentVariable(S"windir");        
DirectoryInfo* info = new DirectoryInfo(S".");
try {      
    Console::WriteLine(S"Directory Info:   {0}", info->FullName);
} __finally {

[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.


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