[C#] How to Get Root Directory in C#

Hello friends !

Now, 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.

string root = @"C:\Temp";
Console.WriteLine(Directory.GetDirectoryRoot(root));

Note: In above program, we need to remember, when we use “Directory” class, System.IOnamespace must be included in the program.

I wish you success, please leave a comment below, we will answer all your questions.

GoodLuck !!!

 

 

 

Xem thêm  [C#] How to Check if a directory Exists

Leave a Reply

Your email address will not be published. Required fields are marked *