Configuration.Save() does not work?

  • Thread starter Thread starter Shannon Richards
  • Start date Start date
S

Shannon Richards

Hello All: I have implemented a custom configuration section in my
app.config file as follows:

<configSections>
<section name="AdminUIConfig"
type="TestMgr.UIConfigSection,TestMgr"/>
</configSections>

<AdminUIConfig name="Admin" caption="Administrator"
captionLC="administrator">
<lookupLayouts>
<lookupLayout name="c1" caption="Administrator" imageIndex="0"
property="FullName" />
<lookupLayout name="c2" caption="Email Address"
property="EmailAddress" />
<lookupLayout name="c3" caption="Insert By" property="InsertBy" />
<lookupLayout name="c4" caption="Insert Date" property="InsertDate"
/>
<lookupLayout name="c5" caption="Update By" property="UpdateBy" />
<lookupLayout name="c6" caption="Update Date" property="UpdateDate"
/>
</lookupLayouts>
</AdminUIConfig>

I can read the configuration properties from my custom section without
issue. When I modify one of the properties in this section programmatically
and save the configuration file nothing seems to happen? The configuration
remains changed while the application is open but when the application
restarts the changes I saved are not available?

I modify and save a property for my custom section as follows:

Dim c As Configuration
Dim s As UIConfigSection
c =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
s = c.GetSection("AdminUIConfig")
s.captionLC = "MODIFIED!"
s.SectionInformation.ForceSave = True
c.Save(ConfigurationSaveMode.Modified)

AM I MISSING SOMETHING?

Thank you,
Shannon Richards
BBA, AIT, MCP
 
All: As it turns out, the issue is not with the code as outlined below...It
is an issue as a result of running the application in the Visual Studio IDE
at design time!

http://msdn2.microsoft.com/en-us/library/ms185331(VS.80).aspx

Basically Visual Studio virtually hosts the application and as a result
utilizes some temporary host files. If you look in the bin directory you'll
notice a myApp.vshost.exe.Config file. When saving configuration changes it
is actually this vshost file that is being updated not the myApp.exe.Config
file. If you open the myApp.vshost.exe.Config while running your project in
the IDE you'll see your configuration changes taking effect.

Running the application as a compiled executable outside the IDE you will
notice it is indeed the myApp.exe.Config that is getting updated.

Shannon Richards
BBA, AIT, MCP
 
Back
Top