Windows Develop Bookmark and Share   
 index > Windows Forms General > How to put application settings from app.config in an external file for windows app
 

How to put application settings from app.config in an external file for windows app

I am using vb.net 2008 for a windows app. All the samples on this problem use web.config not app.config or it is done in another version of .net.

In my app.config I have the following:

<applicationSettings>
<FIOES.My.MySettings>
<setting name="MainImage" serializeAs="String">
<value>Default</value>
</setting>
</FIOES.My.MySettings>
</applicationSettings>

I need to put this in an external config file, but I am getting an error. Here is what I have done in the app.config. I substitute the above with :

<applicationSettings configSource="myappext.config"/>

and in myappext.config I have:

<?xml version="1.0" encoding="utf-8" ?>
<applicationSettings>
<FIOES.My.MySettings>
<setting name="ImageOptions" serializeAs="String">
<setting name="MainImage" serializeAs="String">
<value>Default</value>
</setting>
</FIOES.My.MySettings>
</applicationSettings>

I put this in the same directory as the app.config and in the bin of the project but I receive an error that the app.config cannot be read.

NOTE: I have done this successfully for my connection strings and I am doing the same thing, but I guess it has to be different for application settings.

What do I need to do?

Thanks.
smhaig  Tuesday, March 10, 2009 3:55 AM
After hours of working on this, I have the solution which I will list here:

How to create an external config file for application settings.

app.config

<configSections>

<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >

<section name="FIOES.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />

</sectionGroup>

<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >

<section name="FIOES.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

</sectionGroup>

</configSections>

<applicationSettings>

<FIOES.My.MySettings configSource="FioesAppSettings.config"/>

</applicationSettings>

...

External file -FioesAppSettings.config

<?xml version="1.0" encoding="utf-8" ?>
<FIOES.My.MySettings>
<setting name="ImageOptions" serializeAs="String">
<value>new_or_default</value>
</setting>
<setting name="MainImage" serializeAs="String">
<value>new</value>
</setting>
</FIOES.My.MySettings>




  • Marked As Answer bysmhaig Wednesday, March 11, 2009 1:44 AM
  •  
smhaig  Wednesday, March 11, 2009 1:43 AM
I am wondering if I need to also make changes to the following:

<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="FIOES.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

requirePermission="false" />
</sectionGroup>
</configSections>

This is required in the app.config for the application and user settings and in this way is different from the connection string. However, I keep getting an error that the config file has failed to initialize.

smhaig  Tuesday, March 10, 2009 6:42 PM
After hours of working on this, I have the solution which I will list here:

How to create an external config file for application settings.

app.config

<configSections>

<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >

<section name="FIOES.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />

</sectionGroup>

<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >

<section name="FIOES.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

</sectionGroup>

</configSections>

<applicationSettings>

<FIOES.My.MySettings configSource="FioesAppSettings.config"/>

</applicationSettings>

...

External file -FioesAppSettings.config

<?xml version="1.0" encoding="utf-8" ?>
<FIOES.My.MySettings>
<setting name="ImageOptions" serializeAs="String">
<value>new_or_default</value>
</setting>
<setting name="MainImage" serializeAs="String">
<value>new</value>
</setting>
</FIOES.My.MySettings>




  • Marked As Answer bysmhaig Wednesday, March 11, 2009 1:44 AM
  •  
smhaig  Wednesday, March 11, 2009 1:43 AM

You can use google to search for other answers

Custom Search

More Threads

• ExtenderProvider's properties
• Printing CMR (Transport Form) from VB.Net application
• not able to locate line of code geberating the pb
• Help on simple application ...
• x marks the spot
• [3.0] Non-responsive PictureBox?
• Cannot Modify ToolStripItem Pressed property
• How to make the webbrowser control open links in same window instead of popups
• Custom VS.NET Add-in
• Reference a from from a Class