At run time, the first thing I need to do is write to Project B's
app.config. I've referenced System.configuration.dll within Project
B, and from one of the classes inside Project B's namespace, I'm
trying to use ConfigurationManager to write to its app.config.
Unfortunately, it only finds Project A's app.config. I've even tried
removing Project A's app.config file, but it still can't "see" Project
B's app.config.
Is there any way to accomplish this?
You can access other application configuration files by opening them
directly and then accessing the information in them using the configuration
manager class.
using System.Configuration;
string path = "C:\\MyExecutable.exe"; // The path must be that of your
executable, not the path of the config file.
Configuration config = ConfigurationManager.OpenExeConfiguration(path);
Once the file has been opened, you'll be able to modify it similarly to how
you would normally access the data. Once you're done accessing it just call
the config.Save(); method or the appropriate overload your application
requires. Keep in mind, modifying an application's config file while it's
running will not change the configuration that gets cached once the
ConfigurationManager has been used.
Meaning: if you start project A, and then start project B - use the
ConfigurationManager in project B to access some data in it, and then have
project A modify the configuration for project B - project B's configuration
will not update until the appdomain is reloaded.
HTH,
- Jeff
Error 'System.Configuration.ConfigurationElement.this[System.Configurat
ion.ConfigurationProperty]' is inaccessible due to its protection level
how can i change the protection level of config file to resolve the
issue?
*** Sent via Developersdex http://www.developersdex.com ***