<p>In a .NET Win console application, I would like to access an App.config file in a location different from the console application binary. For example, how can C:\bin\Text.exe get its settings from C:\Test.exe.config?</p>

[{'answer_id': 76067, 'author': 'Santiago Palladino', 'author_id': 12791, 'author_profile': 'https://Stackoverflow.com/users/12791', 'pm_score': 3, 'selected': False, 'text': '<p>Use the following (remember to include System.Configuration assembly)</p>\n\n<pre><code>ConfigurationManager.OpenExeConfiguration(exePath)\n</code></pre>\n'}, {'answer_id': 76071, 'author': 'Michael Meadows', 'author_id': 7643, 'author_profile': 'https://Stackoverflow.com/users/7643', 'pm_score': 2, 'selected': False, 'text': '<p>You can set it by creating a new app domain:</p>\n\n<pre><code>AppDomainSetup domainSetup = new AppDomainSetup();\ndomainSetup.ConfigurationFile = fileLocation;\nAppDomain add = AppDomain.CreateDomain("myNewAppDomain", securityInfo, domainSetup);\n</code></pre>\n'}, {'answer_id': 76085, 'author': 'jeff.willis', 'author_id': 9829, 'author_profile': 'https://Stackoverflow.com/users/9829', 'pm_score': 5, 'selected': True, 'text': '<pre><code>using System.Configuration;    \n\nConfiguration config =\nConfigurationManager.OpenExeConfiguration("C:\\Test.exe");\n</code></pre>\n\n<p>You can then access the app settings, connection strings, etc from the config instance.  This assumes of course that the config file is properly formatted and your app has read access to the directory.  Notice the path is <strong><em>not</em></strong> "C:\\Test.exe.config"  The method looks for a config file associated with the file you specify.  If you specify "C:\\Test.exe.config" it will look for "C:\\Test.exe.config.config"  Kinda lame, but understandable, I guess.</p>\n\n<p>Reference here: <a href="http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.openexeconfiguration.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.openexeconfiguration.aspx</a></p>\n'}, {'answer_id': 18218068, 'author': 'CodeNaked', 'author_id': 142794, 'author_profile': 'https://Stackoverflow.com/users/142794', 'pm_score': 3, 'selected': False, 'text': '<p>It appears that you can use the <a href="http://msdn.microsoft.com/en-us/library/37z40s1c.aspx" rel="nofollow noreferrer"><code>AppDomain.SetData</code></a> method to achieve this. The documentation states:</p>\n\n<blockquote>\n  <p>You cannot insert or modify system entries with this method.</p>\n</blockquote>\n\n<p>Regardless, doing so does appear to work. The documentation for the <a href="http://msdn.microsoft.com/en-us/library/system.appdomain.getdata.aspx" rel="nofollow noreferrer"><code>AppDomain.GetData</code></a> method lists the system entries available, of interest is the <code>"APP_CONFIG_FILE"</code> entry.</p>\n\n<p>If we set the <code>"APP_CONFIG_FILE"</code> before any application settings are used, we can modify where the <code>app.config</code> is loaded from. For example:</p>\n\n<pre><code>public class Program\n{\n    public static void Main()\n    {\n        AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", @"C:\\Temp\\test.config");\n        //...\n    }\n}\n</code></pre>\n\n<p>I found this solution documented in <a href="http://weblogs.asp.net/israelio/archive/2005/01/10/349825.aspx" rel="nofollow noreferrer">this blog</a> and a more complete answer (to a related question) can be found <a href="https://stackoverflow.com/a/6151688/142794">here</a>.</p>\n'}, {'answer_id': 62144686, 'author': 'Balaji Dinakaran', 'author_id': 4890791, 'author_profile': 'https://Stackoverflow.com/users/4890791', 'pm_score': 0, 'selected': False, 'text': '<pre><code>AppDomainSetup domainSetup = new AppDomainSetup();\n        domainSetup.ConfigurationFile = @"D:\\Mine\\Company\\";\n        string browserName = ConfigurationManager.AppSettings["browser"];\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/75978', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2748/']