33

Namely I have:

  • Environment.SpecialFolder.ApplicationData
  • Environment.SpecialFolder.CommonApplicationData
  • Environment.SpecialFolder.LocalApplicationData

I am unclear as to were these point to in Windows XP and/or Windows Vista.

What I found so far is that the ApplicationData points to the ApplicationData Folder for the current user in XP and the roaming application data folder in Vista.

I would also like to know if there are general guidelines on when to use which.

Thorsten Lorenz
  • 11,781
  • 8
  • 52
  • 62

3 Answers3

33

There's no single answer to that. In fact, that's precisely why these "SpecialFolder"s are defined. You use those instead of a hardcoded path.

Environment.SpecialFolder.ApplicationData is the most common one. This folder holds per-user, non-temporary application-specific data, other than user documents. A common example would be a settings or configuration file.

Environment.SpecialFolder.CommonApplicationData is similar, but shared across users. You could use this to store document templates, for instance.

Environment.SpecialFolder.LocalApplicationData is a non-roaming alternative for ApplicationData. As such, you'd never store important data there. However, because it's non-roaming it is a good location for temporary files, caches, etcetera. It's typically on a local disk.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • CommonApplicationData might also be used by websites and services which do not run under a normal user account with a C:\Users\ folder. – Curtis Yallop Oct 15 '13 at 17:58
  • 2
    Note that CommonApplicationData has restricted access making it essentially read-only for all but per-user write privileges. Eg, see http://stackoverflow.com/questions/22107812/privileges-owner-issue-when-writing-in-c-programdata – DAG Mar 11 '16 at 15:14
26

It's easy to check. Use Environment.GetFolderPath(...); and use MessageBox or Console.Write and it will show you where it points too. You only have to make simple app that will display paths for you, and run it under Windows XP and Windows Vista.

using System;

namespace EnvironmentCheck
{
    class Program
    {
        static void Main(string[] args)
    {
        Console.Write(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\n");
        Console.Write(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)+ "\n");
        Console.Write(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)+ "\n");
    }
}
}

My results on Win 7 x64

C:\Users\myUsername\AppData\Roaming
C:\ProgramData
C:\Users\myUsername\AppData\Local

MadBoy
  • 10,824
  • 24
  • 95
  • 156
  • 1
    Thanks for your answer, of course I was aware of that simple app, just that I don't have access to all the different Windows versions, but I need to find settings from other applications installed on the users machine. Thanks for giving me the answer for Win 7, now I'm covered (assuming that it will be the same for Vista) since I'm still running XP. – Thorsten Lorenz Mar 23 '10 at 16:04
  • I noticed that the users.config file is put into C:\Users\myUsername\AppData\Roaming with the company and exe name added to the path. Is there any way to get the company and exe name added to this path or do you have to do it manually? – Josh G Jun 18 '11 at 14:02
  • Can you explain this a bit better what you're looking for? Maybe create new question and elaborate there ? – MadBoy Jun 18 '11 at 16:04
7

For anyone who wants to know what these special folders evaluate to on Windows XP but don't have XP to run it on, here's what I get when running @MadBoy's code:

ApplicationData:

C:\Documents and Settings\YourAccountHere\Application Data

CommonApplicationData:

C:\Documents and Settings\All Users\Application Data

LocalApplicationData:

C:\Documents and Settings\YourAccountHere\Local Settings\Application Data
Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
Oran Dennison
  • 3,237
  • 1
  • 29
  • 37