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

1

0

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.

Havoc answered 15/9, 2015 at 14:6 Comment(0)
L
3

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.

Liberality answered 15/9, 2015 at 14:8 Comment(2)
From the looks of it, it seems that the OP is using .NET 3.5 of lower on Windows XP/2000. They may not have access to this enum member.Wiedmann
Possibly yes. Otherwise the answer would be: not possible. (And if so, it is time to replace it)Liberality

© 2022 - 2024 — McMap. All rights reserved.