views:

59

answers:

1

Hello,

I'm building a custom provider and would like to know how to specify a different configuration file (ex: MyProvider.Config) for my provider to pick the configuration from. By default it is using Web.Config.

Can I specify the path to the custom config file in MyProviderConfiguration class?

Example:

internal class MyProviderConfiguration : ConfigurationSection
{
    [ConfigurationProperty("providers")]        
    public ProviderSettingsCollection Providers
    {
        get
        {
            return (ProviderSettingsCollection)base["providers"];
        }
    }

    [ConfigurationProperty("default", DefaultValue = "TestProvider")]
    public string Default
    {
        get
        {
            return (string)base["default"];
        }
        set
        {
            base["default"] = value;
        }
    }
}

Thank you

-Oleg

A: 

I am not too sure what you want to do. If you just want to load up a config file from a different location you can do the following:

ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
configFileMap.ExeConfigFilename = "<config file path>";

Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);

MyProviderConfiguration customConfig = (MyProviderConfiguration)config.GetSection("

configSectionName");

If you just want to put your custom configuration inside a separate file you can do this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <section name="myProviderConfiguration" type="Namespace.MyProviderConfiguration, AssemblyName" />
    </configSections>
    <myProviderConfiguration configSource="configFile.config" />
</configuration>

And then your configFile.config file would contain:

<?xml version="1.0" encoding="utf-8"?>
<myProviderConfiguration Default="value">
    <Providers>
        <Provider />
    </Providers>
</myProviderConfiguration>

If that doesn't help can you clarify your question further.

Bronumski
To clarify, I don't want to edit Web.Config because provider configuration can be edited on the site by admin users. If I store provider configuration in the Web.config the site will be restated when someone edits provider configuration.I think I can use your ...configSource="configFile.config"... solution. I assume that the site won't be restarted when I edit configFile.config.Thank you for looking into this.
OlegR
Thats correct, editing the seperate file will not cause the web app to restart.
Bronumski