Using this:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
I get this output:
"C:\\Documents and Settings\\[USER]\\Application Data"
How can I get
"C:\\Documents and Settings\\[USER]\\"
?
Using this:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
I get this output:
"C:\\Documents and Settings\\[USER]\\Application Data"
How can I get
"C:\\Documents and Settings\\[USER]\\"
?
Try:
System.IO.Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)).FullName/
Environment.GetEnvironmentVariable("userprofile")
Trying to navigate up from a named SpecialFolder is prone for problems. There are plenty of reasons that the folders won't be where you expect them - users can move them on their own, GPO can move them, folder redirection to UNC paths, etc.
Using the environment variable for the userprofile should reflect any of those possible issues.
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);
}
Though using the environment variable is much more clear.
Messing around with environment variables or hard-coded parent folder offsets is never a good idea when there is a API to get the info you want, call SHGetSpecialFolderPath(...,CSIDL_PROFILE,...)