Where to store Application Data in Windows 7 and Vista

Chris picture Chris · Feb 25, 2011 · Viewed 8.3k times · Source

My application needs to, like most, store data. The application was previously used on XP only where it would store the data in Program Files. Now that our customers are moving to Windows 7 I had to upgrade it so that it stored the data in a new folder. I opted for the ApplicationData folder as I thought I would be allowed access without needing UAC at all.

Now on some Windows 7 machines this is fine, but on others access to the folder fails, presumably because of permissions, but when ran with Administrator privelidges the program works fine.

Am I using the wrong folder or are these cases outliers? In either case what is the best practice for this kind of thing?

I am using the following C# SpecialFolder to get the AppData folder location.

System.Environment.SpecialFolder.ApplicationData

Answer

David Heffernan picture David Heffernan · Feb 25, 2011

System.Environment.SpecialFolder.ApplicationData is per-user and roams. That doesn't sound like what you want. You appear to want machine wide settings and so should use System.Environment.SpecialFolder.CommonApplicationData.

Because CommonApplicationData is shared between all users, the default access control is limited. By default standard users cannot write in this location. The recommended practise is to create a sub-folder of CommonApplicationData at installation time and assign it suitably permissive access control settings.