Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
C# Program to get the name of root directory
Use the RootDirectory property to get the name of the root directory.
Firstly, use DriveInfo to set the drive for which you want the root directory −
DriveInfo dInfo = new DriveInfo("C");
Now, the RootDirectory gives you the result −
dInfo.RootDirectory
Example
Here is the complete code −
using System;
using System.Linq;
using System.IO;
public class Demo {
public static void Main() {
DriveInfo dInfo = new DriveInfo("C");
Console.WriteLine("Root Directory: "+dInfo.RootDirectory);
}
}
Output
The following is the output −
C:\
Advertisements
