[ACCEPTED]-How can i get the path of the current user's "Application Data" folder?-appdata

Accepted answer
Score: 74

Look at combining Environment.GetFolderPath and Environment.SpecialFolder to do this.



Score: 21

Depending on what you are doing you might 4 also want to look at


If the user is on a 3 domain it will only be stored in their local 2 AppData folder and not synced with their roaming 1 profile.

Score: 5

Have a look at the Environment.SpecialFolders


that should get you round 1 the username requirement as well.

Score: 3

Have a look at the System.Environment class 3 and its properties and methods, e.g:

string systemDir = System.Environment.SystemDirectory;
string docs = System.Environment.GetFolderPath(

string systemDrive = System.IO.Path.GetPathRoot(systemDir);

The 2 first one returns "C:\Windows\system32" for example and the 1 second one "C:\Documents and Settings\USERNAME\My Documents".

Score: 2

Try this:

string filePath = Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData);


Score: 1

1)how can i find out the Windows Installation 15 drive in which the user is working.?

    var systemDrive =  Environment.ExpandEnvironmentVariables("%systemdrive%");

I 14 need this to navigate to the ApplicationData 13 in DocumentsandSettings.

You don't really 12 require to fetch the value of either system 11 drive or currently logged in user name to 10 achieve this. There are predefined environment 9 variables %localAppData% and %appData% which give you fully qualified 8 path of these directories as shown in the 7 code below:

var localApplicationData = Environment.ExpandEnvironmentVariables("%localappdata%"); 
//this gives C:\Users\<userName>\AppData\Local

var roamingApplicationData = Environment.ExpandEnvironmentVariables("%appdata%");
//this gives C:\Users\<userName>\AppData\Roaming

2)Also how can i get the user 6 name too so that i can goto ApplicaitionData.? Eg: "D:\Documents 5 and Settings\user\Application Data".

Again, you 4 don't need user name to get the application 3 data path as I've discussed above. Still, for 2 the sake of knowledge you can fetch it from 1 %username% environment variable as shown below:

    var currentUserName = Environment.ExpandEnvironmentVariables("%username%");

More Related questions