Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i am using vb.net for windows application.
i want o know to update the custom tag in config file.
in app config file initially i stored empty string. after my application run time i will replace the empty string into some value.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="tagx" type="System.Configuration.NameValueSectionHandler" />
  </configSections>
  <tagx>
    <add key="key1" value=""/>
  </tagx>
</configuration>


after run my application i want to update the key1 value as "KING".

i searched in net, all the examples giving how to update the appsettings tag value only.
i NO need appsettings updation. i want to update custom tag value.

thanks.

What I have tried:

Dim configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
          Dim settings = CType(configFile.GetSection("tagx"), AppSettingsSection).Settings
          settings("key1").Value = "KING"
          configFile.Save(ConfigurationSaveMode.Modified)           ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name)


but it raise the exception in
Dim settings = CType(configFile.GetSection("tagx"), AppSettingsSection).Settings

unable to cast defaultsettings into appsettings
Posted
Comments
Richard Deeming 8-Jul-21 6:23am    
That's a terrible idea. Your application will most likely be installed into the "Program Files" folder, which most users will not have permission to write to. Your attempts to update your config file will fail.

See this article for suggestions:
Where Should I Store My Data?[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900