I need to store my application config settings in a hierarchical format in web.config or app.config. Is this possible? or I have to store it in some XML file or database and use it instead? plain name value pair format isn't enough for me.
<appSettings>
<Report1>
<add key="SourceFilePath" value="value1" />
<add key="DestinationFolderPath" value="value2" />
</Report1>
<Report2>
<add key="SourceFilePath" value="value1" />
<add key="DestinationFolderPath" value="value2" />
</Report2>
</appSettings>
It is a web-based reporting application and I need to store the file paths for the source files, SSIS packages, FTP server details etc.
Update: If I choose the custom config section option, can I store the settings in a separate file to keep the main web.config file clean from app settings?
You can't add custom elements to appSettings
.
The best way to achieve a custom format it to write your own ConfigurationSettings
class and use that in configuration.
This will allow you to store data in a strongly typed way as well as have meaningful element and attribute names.
See How to: Create Custom Configuration Sections Using ConfigurationSection on MSDN.
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