EDN Admin
Well-known member
Hello,
<br/>
I am converting an applications app.config file to the Settings format (using the designer/properties) where there are 2 sectionGroups: applicationSettings (read-only) and userSettings (read/write). The purpose is so that we may store/load
some settings as user settings that may change over time.
<br/>
I need to read/write settings that are in a secondary config file as userSettings. For example, by default the setting will be read from this secondary file, but if the setting is changed, the new setting will be read from the user.config file. Can
this be done? If so, can it be done without changing the secondary config files current format?
<br/>
Problems:
<br/>
1. Looking at the LoggerUdpSettings definitions in the new app.config below, I have to change the tag name to "<AppName.Properties.LoggerUdpSettings>" in Logger.UdpSettings.config in order to access the values.
<br/>
2. Since Logger.UdpSettings.config is set up with key value pairs, I changed the section type to NameValueSectionHandler. However, this appears to take away my ability to change/save these settings like I can with the "TestUserSetting" below.
<br/>
<br/>
Below is how some settings are currently linked from the main app to another config file using configSource, followed by my attempt at a new app.config:
<br/>
Old app.config:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; utf-8<span style="color:Black; " <span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; configuration<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; configSections<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; sectionGroup <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; IS.Support.Logger<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; section <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; UdpSettings<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; System.Configuration.NameValueSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089<span style="color:Black; " <span style="color:Red; requirePermission<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; false<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; sectionGroup<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; configSections<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; IS.Support.Logger<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; UdpSettings <span style="color:Red; configSource<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Logger.UdpSettings.config<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; IS.Support.Logger<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; configuration<span style="color:Blue; >
[/code]
<br/>
External config Logger.UdpSettings.config:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; utf-8<span style="color:Black; " <span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; UdpSettings<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; DebugUdpAppenderPort<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 64000<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; UserLocalUdpAppenderPort<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 64001<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; UserBroadcastUdpAppenderPort<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 64002<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; MulticastAddress<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 9.9.9.9<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; UdpSettings<span style="color:Blue; >
[/code]
<br/>
New app.config:
<br/>
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; utf-8<span style="color:Black; " <span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; configuration<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; configSections<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; sectionGroup <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; applicationSettings<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089<span style="color:Black; " <span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; section <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; AppName.Properties.Settings<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089<span style="color:Black; " <span style="color:Red; requirePermission<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; false<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; sectionGroup<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; sectionGroup <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; userSettings<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089<span style="color:Black; " <span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; section <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; AppName.Properties.LoggerUdpSettings<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; System.Configuration.NameValueSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089<span style="color:Black; " <span style="color:Red; allowExeDefinition<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; MachineToLocalUser<span style="color:Black; " <span style="color:Red; requirePermission<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; false<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; section <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; AppName.Properties.Settings<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089<span style="color:Black; " <span style="color:Red; allowExeDefinition<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; MachineToLocalUser<span style="color:Black; " <span style="color:Red; requirePermission<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; false<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; sectionGroup<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; configSections<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; applicationSettings<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; AppName.Properties.Settings<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; setting <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; TestAppSetting<span style="color:Black; " <span style="color:Red; serializeAs<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; String<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; value<span style="color:Blue; >default value<span style="color:Blue; </<span style="color:#A31515; value<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; setting<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; AppName.Properties.Settings<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; applicationSettings<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; userSettings<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; AppName.Properties.LoggerUdpSettings <span style="color:Red; configSource<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Logger.UdpSettings.config<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; AppName.Properties.Settings<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; setting <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; TestUserSetting<span style="color:Black; " <span style="color:Red; serializeAs<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; String<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; value<span style="color:Blue; >default value<span style="color:Blue; </<span style="color:#A31515; value<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; setting<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; AppName.Properties.Settings<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; userSettings<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; configuration<span style="color:Blue; >
[/code]
<br/>
Thanks.
View the full article
<br/>
I am converting an applications app.config file to the Settings format (using the designer/properties) where there are 2 sectionGroups: applicationSettings (read-only) and userSettings (read/write). The purpose is so that we may store/load
some settings as user settings that may change over time.
<br/>
I need to read/write settings that are in a secondary config file as userSettings. For example, by default the setting will be read from this secondary file, but if the setting is changed, the new setting will be read from the user.config file. Can
this be done? If so, can it be done without changing the secondary config files current format?
<br/>
Problems:
<br/>
1. Looking at the LoggerUdpSettings definitions in the new app.config below, I have to change the tag name to "<AppName.Properties.LoggerUdpSettings>" in Logger.UdpSettings.config in order to access the values.
<br/>
2. Since Logger.UdpSettings.config is set up with key value pairs, I changed the section type to NameValueSectionHandler. However, this appears to take away my ability to change/save these settings like I can with the "TestUserSetting" below.
<br/>
<br/>
Below is how some settings are currently linked from the main app to another config file using configSource, followed by my attempt at a new app.config:
<br/>
Old app.config:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; utf-8<span style="color:Black; " <span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; configuration<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; configSections<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; sectionGroup <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; IS.Support.Logger<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; section <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; UdpSettings<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; System.Configuration.NameValueSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089<span style="color:Black; " <span style="color:Red; requirePermission<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; false<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; sectionGroup<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; configSections<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; IS.Support.Logger<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; UdpSettings <span style="color:Red; configSource<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Logger.UdpSettings.config<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; IS.Support.Logger<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; configuration<span style="color:Blue; >
[/code]
<br/>
External config Logger.UdpSettings.config:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; utf-8<span style="color:Black; " <span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; UdpSettings<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; DebugUdpAppenderPort<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 64000<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; UserLocalUdpAppenderPort<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 64001<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; UserBroadcastUdpAppenderPort<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 64002<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; MulticastAddress<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 9.9.9.9<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; UdpSettings<span style="color:Blue; >
[/code]
<br/>
New app.config:
<br/>
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; utf-8<span style="color:Black; " <span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; configuration<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; configSections<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; sectionGroup <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; applicationSettings<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089<span style="color:Black; " <span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; section <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; AppName.Properties.Settings<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089<span style="color:Black; " <span style="color:Red; requirePermission<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; false<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; sectionGroup<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; sectionGroup <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; userSettings<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089<span style="color:Black; " <span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; section <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; AppName.Properties.LoggerUdpSettings<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; System.Configuration.NameValueSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089<span style="color:Black; " <span style="color:Red; allowExeDefinition<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; MachineToLocalUser<span style="color:Black; " <span style="color:Red; requirePermission<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; false<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; section <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; AppName.Properties.Settings<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089<span style="color:Black; " <span style="color:Red; allowExeDefinition<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; MachineToLocalUser<span style="color:Black; " <span style="color:Red; requirePermission<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; false<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; sectionGroup<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; configSections<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; applicationSettings<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; AppName.Properties.Settings<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; setting <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; TestAppSetting<span style="color:Black; " <span style="color:Red; serializeAs<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; String<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; value<span style="color:Blue; >default value<span style="color:Blue; </<span style="color:#A31515; value<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; setting<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; AppName.Properties.Settings<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; applicationSettings<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; userSettings<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; AppName.Properties.LoggerUdpSettings <span style="color:Red; configSource<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Logger.UdpSettings.config<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; AppName.Properties.Settings<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; setting <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; TestUserSetting<span style="color:Black; " <span style="color:Red; serializeAs<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; String<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; value<span style="color:Blue; >default value<span style="color:Blue; </<span style="color:#A31515; value<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; setting<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; AppName.Properties.Settings<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; userSettings<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; configuration<span style="color:Blue; >
[/code]
<br/>
Thanks.
View the full article