Now in this tutorial, we will learn How to Get Root Directory in C #.
The GetRootDirectory method returns the root directory of the specified directory. The code below, we will learn how to get root directory of given directory using C# code? To get root directory, we have to use static method GetDirectoryRoot() of Directory class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | class Program { static void Main(string[] args) { string root = @"D:\Images\2017\summer\"; Console.WriteLine(root); Console.WriteLine(Directory.GetDirectoryRoot(root)); Console.ReadLine(); } } |
Output: