# .net – Using environment variables for .config file in .NET

.net

I need to specify path to dlls referenced by assembly in .config file.
Problem is that path can be found in env. variable.
Is it possible to use some sort of %DLLPATH% macro in .config file?

#### Best Solution

Yes, that's possible! Suppose you have something like that in your config:

<configuration>
<appSettings>

var pathFromConfig = ConfigurationManager.AppSettings["mypath"];

ExpandEnvironmentVariables(string s) does the magic by replacing all environment variables within a string with their current values.