Loading non-default configuration file

Topics: Enterprise Library Core, General discussion
Oct 26, 2010 at 7:43 PM

Good afternoon,

I'm trying to set, at runtime, the configuration file that is loaded by the EntLib. The scenario I'm working on is this: We have multiple users, utilizing roaming profiles, each with their own, custom configuration file. So, within the roaming profile is a configuration file that I want to use to configure my winforms app. I'd like to be able to pass the path to that user-specific config file to the EntLib and have it override the current (default) configuration. I swear I put together a proof of concept for this problem; however, I can't seem to find it now. Can you point me int he right direction on this?

Thanks,

Jon

Oct 26, 2010 at 10:29 PM

If you're using Entlib 5.0, you will create a FileConfigurationSource passing the path and filename of the configuration file you want to use and set the EnterpriseLibraryContainer.Current property to use it:

IConfigurationSource configSource = new FileConfigurationSource("user.config");
EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);

If you're using lower versions, you would also deal with FileConfigurationSource and each block's factory class.  See this blog for more info on this.

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@Avanade.com