Reputation: 23275
If you are deploying an app which uses a file-based database such as SQLite or Access-MDB, where should the database files be deployed to on a machine, bearing in mind that the app will need full access to this location?
Don't MS guidelines say that the %PROGRAMFILES%
folder should only contain read-only application files?
Where should database files be placed? In the %APPDATA%
folder?
Upvotes: 1
Views: 301
Reputation: 81610
You definitely should not be using the Program Files
directory anymore to store dynamic information.
This Windows Blog User Account Control Data Redirection gives a nice summary:
Ensure that you do not hard-code paths once you have determined the appropriate locations. Instead, use one of the following programming models and APIs to retrieve the correct paths of specific Windows known folders:
C/C++ native applications: Use the SHGetKnownFolderPath function that retrieves the full path of a known folder identified by the folder's KNOWNFOLDERID, a GUID parameter indicating the known location you would like to obtain:
- FOLDERID_ProgramData – Shared program data directory for all users
- FOLDERID_LocalAppData – Per-user program data directory (non-roaming)
- FOLDERID_RoamingAppData – Per-user program data directory (roaming)
Managed Code: Use the System.Environment.GetFolderPath function. GetFolderPath takes a parameter indicating the Known Location you would like to obtain:
- Environment.SpecialFolder.CommonApplicationData – Shared program data directory for all users
- Environment.SpecialFolder.LocalApplicationData – Per-user program data directory (non-roaming)
- Environment.SpecialFolder.ApplicationData – Per-user program data directory (roaming)
If none of the above-mentioned options are available, use the environment variable:
- %ALLUSERSPROFILE% – Shared program data directory for all users
- %LOCALAPPDATA% – Per-user program data directory (non-roaming) - Windows Vista or later
- %APPDATA% – Per-user program data directory (roaming) - Windows Vista or later
Upvotes: 1