What's the SpecialFolder enum member that has the base directory for the user?

孤街醉人 提交于 2021-01-29 07:20:00

问题


As far as I understand these are the best examples for each of the SpecialFolder members:

Desktop                 C:\Documents and Settings\ibboard\Desktop
Programs                C:\Documents and Settings\ibboard\Start Menu\Programs
Personal                C:\Documents and Settings\ibboard\My Documents
MyDocuments             C:\Documents and Settings\ibboard\My Documents
Favorites               C:\Documents and Settings\ibboard\Favorites
Startup                 C:\Documents and Settings\ibboard\Start Menu\Programs\Startup
Recent                  C:\Documents and Settings\ibboard\Recent
SendTo                  C:\Documents and Settings\ibboard\SendTo
StartMenu               C:\Documents and Settings\ibboard\Start Menu
MyMusic                 C:\Documents and Settings\ibboard\My Documents\My Music
DesktopDirectory        C:\Documents and Settings\ibboard\Desktop
MyComputer
Templates               C:\Documents and Settings\ibboard\Templates
ApplicationData         C:\Documents and Settings\ibboard\Application Data
LocalApplicationData    C:\Documents and Settings\ibboard\LocalSettings\Application Data
InternetCache           C:\Documents and Settings\ibboard\Local Settings\Temporary Internet Files
Cookies                 C:\Documents and Settings\ibboard\Cookies
History                 C:\Documents and Settings\ibboard\Local Settings\History
CommonApplicationData   C:\Documents and Settings\All Users\Application Data
System                  C:\WINDOWS\system32
ProgramFiles            C:\Program Files
MyPictures              C:\Documents and Settings\ibboard\My Documents\My Pictures
CommonProgramFiles      C:\Program Files\Common Files

(Assuming the username is called ibboard)

So, there's no way to get the base user directory C:\Documents and Settings\ibboard? Really??? Don't tell me I need to "cd .." please.


回答1:


You missed to mention UserProfile, which is available since .NET 4, which will yield the user's directory:

string userDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

From MSDN (emphasis mine):

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. Added in the .NET Framework 4.



来源:https://stackoverflow.com/questions/32588217/whats-the-specialfolder-enum-member-that-has-the-base-directory-for-the-user

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!