C# Program to Get the Full Path of the Current Directory Using Environment Class
In C#, Environment Class provides information about the current platform and manipulates, the current platform. It is useful for getting and setting various operating system-related information. We can use it in such a way that it retrieves command-line arguments information, exit codes information, environment variable settings information, contents of the call stack information, and time since the last system boot in milliseconds information. In this article, we will discuss how to get the full path of the current directory. So to solve this problem we use the CurrentDirectory property of the Environment Class. This property returns the complete path of the current working directory of your computer. This property also throws the following exceptions:
- ArgumentException: This exception is thrown when the CurrentDirectory property tries to set to an empty string.
- ArgumentNullException: This exception is thrown when the CurrentDirectory property tries to set to null.
- IOException: This exception is thrown when the input/output error occurred.
- DirectoryNoFoundException: This exception is thrown when the CurrentDirectory property tries to set a local path/address that cannot be found.
- SecurityException: This exception is thrown when the caller does not have suitable permission.
Return Type: The return type of this property is a string. And the returned string represents the current directory path.
System Directory: /Users/Projects/newprogram/