juan juan - 6 months ago 52
C# Question

How can I get the current user directory?

Using this:


I get this output:

"C:\\Documents and Settings\\[USER]\\Application Data"

How can I get the root directory of all users? i.e.:

"C:\\Documents and Settings\\[USER]\\"


May be this will be a good solution: taking in account whether this is Vista/Win7 or XP and without using environment variables:

string path = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)).FullName;
if ( Environment.OSVersion.Version.Major >= 6 ) {
    path = Directory.GetParent(path).ToString();

Though using the environment variable is much more clear.