ConfigurationManager will not automatically expand anything in the application settings, as these are just free-form strings, but you can do it manually. Use the ExpandEnvironmentVariables Environment method, which will expand the %VARIABLENAME% form variables to match the current environment. So:
<appSettings> <add key="Database" value="sqlite:///%APPDATA%\database\test.db3" /> </appSettings> string path = Environment.ExpandEnvironmentVariables(ConfigurationManager.AppSettings["Database"]);
The root path to your home directory is in the% USERPROFILE% variable, although% APPDATA% is a traditional place to talk about what you are talking about. There is also% ALLUSERSPROFILE% for system-wide data (although on Windows 7, which actually points to a special system-wide data folder, not the "Public" profile.)
source share