问题
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