Environment.GetFolderPath (Environment.SpecialFolder.SOMETHING)

I've tried most of the enumeration Enviroment.SpecialFolder

, but I think there is no way to do what I would like to do with just the enum. Using the method string.Substring()

brought me even more.

I am trying to get only the path to the system partition where windows are actually installed. On machine A it might be C:\

, on machine B it might be D:\

.

The most suitable solution I have found so far was

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

      

Is there a better way to do this? Thank.

+3


source to share


2 answers


To get the disc, 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));

      

+8


source


If you want "disk where Environment.SpecialFolder.Windows" is, your sample is fine.

You can use Path.GetPathRoot instead of Susbstring ...



Note that you probably shouldn't write anything to the root disk yourself (if your program is designed to behave well).

+3


source







All Articles