K
Kerr
Hi all,
I've been scouring the internet for help with this problem and every
occurance i've seen reconstructs the problem but no one seems to have a
solution. Hoping that you guys can help me.
I have a vb.net windows forms project that is using a app.config file.
the contents of the app.config is staggered. see a snippet below:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<!-- tell .NET Framework to ignore CLR sections -->
<section name="frisbee"
type="System.Configuration.NameValueFileSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="frmBatching"
type="System.Configuration.NameValueFileSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="frmFiltering"
type="System.Configuration.NameValueFileSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="frmConfig"
type="System.Configuration.NameValueFileSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="frmSupporting"
type="System.Configuration.NameValueFileSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<frisbee>
<add key="intErrorLogtype" value="1" />
<add key="EventLogKeyName" value="FRISBEE" />
<add key="SQLDBConnString" value="" />
<add key="sys_DBCheck" value="usp_CheckSQLConnection" />
<add key="Maximised" value="true" />
</frisbee>
<frmBatching>
<add key="height" value="" />
<add key="width" value="" />
<add key="top-left-position" value="" />
<add key="ImgDir" value="" />
<add key="BatchDir" value="" />
<add key="ImgInBatch" value="" />
<add key="BatchNo" value="" />
<add key="Maximised" value="true" />
</frmBatching>
Now to read values out of this staggered app.config file i use the
specialised.namevaluecollection in the following manner
Dim objConfigNV As New Specialized.NameValueCollection
Dim strConfigValue As String = Convert.ToString(vbNullString)
objConfigNV = CType(ConfigurationSettings.GetConfig(strIDicName),
Specialized.NameValueCollection)
strConfigValue = Convert.ToString(objConfigNV(strKeyName))
And this works fine.
Now.. the problem..
to write a value back to the app.config file using the same
Specialized.NamevalueCollection in the following manner:
'initialise collection object of app.config
Dim objNameValue As New Specialized.NameValueCollection
'app.ocnfig is staggered. this gets the relevant sectoin on
file
objNameValue =
CType(ConfigurationSettings.GetConfig("frmSupporting"),
Specialized.NameValueCollection)
'this sets the the new value of a key
objNameValue(strKey) = strValue
Generates an exception: Collection is read-only
Does ANYONE have any ideas how to create an instance of a
NameValueCollection that is not read-only so that I can write back to my
app.config file.
Any help on this would be greatly appreciated.
Kerr
I've been scouring the internet for help with this problem and every
occurance i've seen reconstructs the problem but no one seems to have a
solution. Hoping that you guys can help me.
I have a vb.net windows forms project that is using a app.config file.
the contents of the app.config is staggered. see a snippet below:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<!-- tell .NET Framework to ignore CLR sections -->
<section name="frisbee"
type="System.Configuration.NameValueFileSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="frmBatching"
type="System.Configuration.NameValueFileSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="frmFiltering"
type="System.Configuration.NameValueFileSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="frmConfig"
type="System.Configuration.NameValueFileSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="frmSupporting"
type="System.Configuration.NameValueFileSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<frisbee>
<add key="intErrorLogtype" value="1" />
<add key="EventLogKeyName" value="FRISBEE" />
<add key="SQLDBConnString" value="" />
<add key="sys_DBCheck" value="usp_CheckSQLConnection" />
<add key="Maximised" value="true" />
</frisbee>
<frmBatching>
<add key="height" value="" />
<add key="width" value="" />
<add key="top-left-position" value="" />
<add key="ImgDir" value="" />
<add key="BatchDir" value="" />
<add key="ImgInBatch" value="" />
<add key="BatchNo" value="" />
<add key="Maximised" value="true" />
</frmBatching>
Now to read values out of this staggered app.config file i use the
specialised.namevaluecollection in the following manner
Dim objConfigNV As New Specialized.NameValueCollection
Dim strConfigValue As String = Convert.ToString(vbNullString)
objConfigNV = CType(ConfigurationSettings.GetConfig(strIDicName),
Specialized.NameValueCollection)
strConfigValue = Convert.ToString(objConfigNV(strKeyName))
And this works fine.
Now.. the problem..
to write a value back to the app.config file using the same
Specialized.NamevalueCollection in the following manner:
'initialise collection object of app.config
Dim objNameValue As New Specialized.NameValueCollection
'app.ocnfig is staggered. this gets the relevant sectoin on
file
objNameValue =
CType(ConfigurationSettings.GetConfig("frmSupporting"),
Specialized.NameValueCollection)
'this sets the the new value of a key
objNameValue(strKey) = strValue
Generates an exception: Collection is read-only
Does ANYONE have any ideas how to create an instance of a
NameValueCollection that is not read-only so that I can write back to my
app.config file.
Any help on this would be greatly appreciated.
Kerr