I'm new to tinkering with app.config and xml, and am currently doing some refactoring in some code I haven't written.
Currently we have a snippet which looks like this:
<setting name="FirstSetting" serializeAs="String">
<value>Data Source=C:\Documents and Settings\All Users\ApplicationData\Company ...;Persist Security Info=False</value>
What I'd like to do is have it instead point to something like ${PROGRAMDATA}\Company\...
How can I achieve this, keeping in mind that PROGRAMDATA will not always point to C:\ProgramData ?
use
Environment.ExpandEnvironmentVariables(stringFromConfig);
it replaces all existing environment variables in the string like %ProgramData% with the exact values.
I didn't really want to change it in code as per the other responses, since that removes the purpose of having it as a config setting.
As it turns out, %ProgramData%\Company... is the proper way of using environment variables in this context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With