why the specialfolder.personal return c:/user/xxx/Documents
I expect the specialfolder.personal returns c:/users/xxx, however in my Windows 7 system, it returns c:/user开发者_开发技巧s/xxx/Documents. Why? How to get the folder of personal root directory?
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");
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);
精彩评论