Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment.GetFolderPath(Environment.SpecialFolder.SOMETHING)

Tags:

c#

.net

I've been trying out the most of the Enviroment.SpecialFolder enumeration, but I think there isn't any way of what I'd like to accomplish with the enumeration only. Using the string.Substring() method brought me the farest, yet.

I try to get just the system partition path, where windows is actually installed. On machine A it might be C:\, on machine B it might be D:\.

The most sufficent solution, I found so far was

var path = Environment.GetFolderPath(Environment.SpecialFolder.Windows)
                      .Substring(0, 3);

Is there a better way to do this? Thanks.

like image 600
Michael Schnerring Avatar asked Jun 11 '26 13:06

Michael Schnerring


1 Answers

To get the drive, use Path.GetPathRoot. See http://msdn.microsoft.com/en-us/library/system.io.path.getpathroot.aspx

var root = Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.Windows));
like image 52
Richard Schneider Avatar answered Jun 14 '26 01:06

Richard Schneider