How do you detect the main hard drive letter such as C: drive?

This should work (assuming you want the drive that windows is on):

string rootDrive = Path.GetPathRoot(Environment.SystemDirectory);

Environment.GetFolderPath(Environment.SpecialFolder.System).Substring(0,1)

Reference from here.


Try

Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System));

That will return (normally) C:\

But it depends on how you define the "main" hard drive. This will give you the drive Windows is installed on.

Tags:

C#