I have created child nodes in app.config.xml file:
<applicationSettings>
<XML.My.MySettings>
<setting name="Astrology" serializeAs="String">
<value></value>
</setting>
<setting name="Cricket" serializeAs="String">
<value></value>
</setting>
<setting name="ForiegnCurrency" serializeAs="String">
<value></value>
</setting>
<setting name="Jobs" serializeAs="String">
<value></value>
</setting>
</XML.My.MySettings>
</applicationSettings>

I want to insert values in this child nodes
Astrology=6:00
Cricket=7:00
ForeignCurrency=8:00
Jobs=9:00

How to read and insert values in this xml child nodes?
in VB.NET2005

Dani AI

Generated

A few practical paths to fill those setting nodes, plus the usual pitfalls that cause the configuration error saw. ’s suggestion to use the project Settings designer is the easiest when you want typed accessors; if you need to change the config XML itself at runtime, use one of the two approaches below and validate the file first.

Programmatic (Configuration API)
Use the System.Configuration types to open the exe config, get the settings section (the path is applicationSettings/<fullSectionName>), edit or add the SettingElement.Value, save and refresh the section. This keeps the runtime model consistent with the config system; see Microsoft’s guide on accessing configuration programmatically and the OpenExeConfiguration API for exact details:

ConfigurationManager.OpenExeConfiguration

Direct XML edit (XmlDocument / XDocument)
If you prefer simple XML edits, load the running app’s config file (AppDomain.CurrentDomain.SetupInformation.ConfigurationFile), locate the setting[@name='...']/value node with XPath, set its InnerText and save. This is straightforward but you must not break the overall config structure.

Troubleshooting tips

  • If the configuration system fails to initialize, check for malformed XML, missing/incorrect <configSections> declarations, or stray characters (BOM) at the top of the file.
  • Confirm the correct section path (the full section name is generated by the Settings designer).
  • After saving with the Configuration API call ConfigurationManager.RefreshSection(...) or restart the app to pick up changes.
  • If the app runs from protected folders, write permission will fail; prefer user-scoped settings or a separate writable file.

Back up the config before editing. If the Settings designer route is acceptable, create the settings there first — it avoids most manual XML issues.

Recommended Answers

All 3 Replies

You can read from both user and application settings but you can only write (save) user settings

To Read:
Dim Value as StringValue = My.Settings.Astrology
Value = My.Settings.Cricket
Value = My.Settings.ForeignCurrency
Value = My.Settings.Jobs


To Write:
My.Settings.Astrology = "6:00"
My.Settings.Cricket = "7:00"
My.Settings.ForeignCurrency = "8:00"
My.Settings.Jobs = "9:00"

But for XMLs other than the Settings Config i would use Datatable.readXML and Datatable.WriteXML as datatables allow better data control

You can read from both user and application settings but you can only write (save) user settings

To Read:
Dim Value as StringValue = My.Settings.Astrology
Value = My.Settings.Cricket
Value = My.Settings.ForeignCurrency
Value = My.Settings.Jobs


To Write:
My.Settings.Astrology = "6:00"
My.Settings.Cricket = "7:00"
My.Settings.ForeignCurrency = "8:00"
My.Settings.Jobs = "9:00"

But for XMLs other than the Settings Config i would use Datatable.readXML and Datatable.WriteXML as datatables allow better data control

I tried it but it gave me error on
Dim Value as StringValue = My.Settings.Astrology
so I made it
Dim Value As String = My.Settings.Astrology
But now it shows an error
Configuration system failed to initialize
Please help!!!!!

For Dim Value As String = My.Settings.Astrology

The setting must by in setup in the Settings Tab of "My Project" area

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.