I need to parse a config file that is situated in another project. I know that ConfigurationManager reads the app.config file by default, but how to make it read that particular config file?
It appears there is a way to do this in . NET 3.5 by setting the allowOverride attribute in the appSettings definition section of machine. config. This allows you to override the entire section in your own app.
The web. config file is required for ASP.NET webpages. The app. config file is optional in an application and doesn't have to be used when writing desktop applications.
In Solution Explorer, right-click the project node, and then select Add > New Item. The Add New Item dialog box appears. Expand Installed > Visual C# Items. In the middle pane, select the Application Configuration File template.
// Create a filemap refering the config file.
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = configFilePath;
// Retrieve the config file.
Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
Or like this:
var fileMap = new ConfigurationFileMap(configFilePath);
Configuration config = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
But you still will have a problem with custom configuration sections.
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