Environment.SystemDirectory
This property is available in the Environment Class. It provides an information about the working environment like variables, methods used, and system related information in C#.
The SystemDirectory property is used to return the full path where the file is stored. It is possible to store the C# files in any number of folders starting from the root folder like inside C drive, D drive, etc.
Syntax:
string Environment.SystemDirectory
Return:
Return the entire path.
Example 1:
Let’s store the file in the previously specified path and run it.
class Linuxhint {
//let's implement SystemDirectory property inside main method
static public void Main() {
//get the path in which the program file is resided.
Console.WriteLine("Path: "+Environment.SystemDirectory);
}
}
Output:
Explanation:
We implement the property inside the main() method.
Line 6: Console.WriteLine(“Path: “+Environment.SystemDirectory);
We directly return the path without storing it in the variable.
Example 2:
We can also store the path into a string type variable and return it.
class Linuxhint {
//let's implement SystemDirectory property inside main method
static public void Main() {
//get the path in which the program file is resided.
string way=Environment.SystemDirectory;
Console.WriteLine("Path: "+way);
}
}
Output:
We create a string variable “way”, store and display the path.
Explanation:
We implement the property inside the main() method.
Line 6: string way=Environment.SystemDirectory;
We store the path inside the variable “way”.
Line 7: Console.WriteLine(“Path: “+way);
Display the path present in the variable using the Console.WriteLine().
Conclusion
With this article, we came to know that it is possible to return the path where our C# file is located in our system using the Environment.SystemDirectory property. It returns the path in the form of a string. You can implement this in your machine and get to know your file path.