juan juan - 1 year ago 108
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]\\"

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download