views:

19

answers:

1

Hi,

In a small test project, I currently have the provider sections in the web.config. I want to move that to a separate config file, like providers.config. My current provider instantiation code is like:

   //Get the feature's configuration info
                    ProviderConfiguration pc = (ProviderConfiguration)ConfigurationManager.GetSection(DATA_PROVIDER_NAME);

This code works if the provider info is in web.config, but how to I read this info from another file (like providers.condfig) because it seems that the ConfigurationManager "reads" only web.config file. I may be missing something very simple here :)

Would love to get more inputs on this.

Thanks V

A: 

If you want to reference an external file for a collection of settings in the web.config you can do this:

<?xml version="1.0"?>
<configuration>

<appSettings file="externalSettings.config"/>

<connectionStrings/>

<system.web>

    <compilation debug="false" strict="false" explicit="true" />

</system.web>

Hope this helps.

So in your case you can do something like this:

 <configSections>
    <section name="ProviderName" type="System.Configuration.NameValueSectionHandler" />
  </configSections>
  <ProviderName file="provider.config" />
Richard
thanks Richard, I am aware of the file or configsource attributes :). But here the problem is provider sections, like:<section name="MyProvider" type="xx" /><MyProvider ....><add ...> </MyProvider>
Vivek
Richard, I think I did not make my question clear, apologies for it. Actually if I use the file name, then I would have to do that for EVERY provider, something which i was thinking of getting rid off. Basically I dont even want to mention ANY provider section (not even <section name=""...> stuff) in the web.config. I want all that info in another config class
Vivek

related questions