I expect the specialfolder.personal returns c:/users/xxx, however in my Windows 7 system, it returns c:/users/xxx/Documents. Why? How to get the folder of personal root directory?
Asked
Active
Viewed 3,482 times
2
-
Have you tried `UserProfile` ? – leppie Nov 10 '10 at 04:54
2 Answers
4
From the documentation:
Personal: The directory that serves as a common repository for documents. This member is equivalent to MyDocuments.
Instead, you want SpecialFolder.UserProfile
.
UserProfile: The user's profile folder. Applications should not create files or folders at this level; they should put their data under the locations referred to by ApplicationData.
Update
Apparently, this only works in .NET 4. So instead, try this:
System.Environment.GetEnvironmentVariable("UserProfile");

jordanbtucker
- 5,768
- 2
- 30
- 43
-
-
It is working by using Environment.GetEnvironmentVariable(@"USERPROFILE") – user496949 Nov 10 '10 at 05:16
-
-
Good point. I was thinking of [ExpandEnvironmentVariables](http://msdn.microsoft.com/en-us/library/system.environment.expandenvironmentvariables.aspx). – jordanbtucker Nov 10 '10 at 05:21
-
1
-
1@kdbanman My guess is because it's not part of the user's roaming profile like ApplicationData is. LocalApplicationData is the non-roaming counter part. Also, it's not necessarily off limits, just not usually the best place. – jordanbtucker Jul 17 '15 at 03:42
1
Have you tried:
Environment.GetFolderPath (System.Environment.SpecialFolder.UserProfile)
Edit: this emum member is present only in Framework 4.0. In earler Framework versions, the following should give the same result:
void Main()
{
var lpszPath = new StringBuilder(260);
const int UserProfile = 40;
SHGetFolderPath (IntPtr.Zero, UserProfile, IntPtr.Zero, 0, lpszPath);
string answer = lpszPath.ToString();
}
[DllImport("shfolder.dll", CharSet=CharSet.Auto)]
internal static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder, IntPtr hToken, int dwFlags, StringBuilder lpszPath);

Joe Albahari
- 30,118
- 7
- 80
- 91