Using App.Config with Windows Serives


Given that this just boiled my brain I though i’d share:
 
//this doesn’t work with windows services

ConfigurationManager.AppSettings["SettingName"];

//this does

//set it up
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationSectionGroup configSection = config.SectionGroups["applicationSettings"];
ClientSettingsSection configSectionApplicationSettings = (ClientSettingsSection)configSection.Sections["[namespace].Properties.Settings"];
SettingElementCollection configSettings = configSectionApplicationSettings.Settings;

//get a setting
configSettings.Get("Setting Name").Value.ValueXml.InnerText

Advertisements

Author: Stuart

Crazy Person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s