Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

storing hierarchical application settings in web.config or app.config

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?

like image 945
RKP Avatar asked Feb 03 '23 09:02

RKP


1 Answers

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.

like image 140
Oded Avatar answered Feb 05 '23 18:02

Oded