How do I load the App.config file?
I am parsing the project's app.config file. This config file is loaded from the caller project. Inside the called project, I have something like:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("app.config");
// Some parsing...
Unfortunately, the app.config file is not located correctly. Apparently the Load method looks in the ~ / bin / Release directory of the caller project, but the app.config file is in the ~ directory.
Is there a way to load the App.config file correctly?
thanks
a source to share
I don't understand why you need this. The config file is App.Config
copied to the runtime directory at build time and renamed yourapplicationname.exe.config
.
You can use a class ConfigurationManager
to access the contents of this file.
a source to share
The correct way to load configuration information is to use types in the namespace System.Configuration
. Do not disassemble it yourself. For many types, you will also need a link System.Configuration.dll
.
Visual Studio should copy the file named app.config
into the output directory when it is created. It renames the file to <assembly_name>.config
, so if you build myapp.exe
then the config file will be myapp.exe.config
. Make sure the file properties are set to "Build Action: None, Copy to output directory: do not copy". VS sees this as a special case. Don't override it.
a source to share