Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to store Application Data in Windows 7 and Vista

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
like image 649
Chris Avatar asked Feb 25 '11 11:02

Chris


People also ask

Where is app data located in Windows 7?

To open the AppData folder on Windows 10, 8 & 7: Open File Explorer/Windows Explorer. Type %AppData% into the address bar and hit enter. Navigate to the required folder (Roaming or Local)

Where is app data stored in PC?

The AppData folder contains custom settings and other information that PC system applications need for their operation. It is a hidden folder that includes application settings, files, and data unique to different applications on your computer. This includes all the data specific to your Windows OS user profile.

Where is the app data folder?

AppData is a hidden folder located in C:\Users\<username>\AppData. The AppData folder contains custom settings and other information needed by applications. For example, you might find the following in your AppData folder: Web browser bookmarks and cache.


2 Answers

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.

like image 134
David Heffernan Avatar answered Oct 26 '22 09:10

David Heffernan


David is right. As far I know, there's also some difference if you deploy your app via ClickOnce or Installer: the first allows a few subset of permissions than the normal installer. I must confess I'm not an expert on that.

Of sure, Program Files is the worst place to store data, even since XP.

like image 28
Mario Vernari Avatar answered Oct 26 '22 10:10

Mario Vernari