I have an app.config in my project and I want to add some items, but I don't want to use the "appSettings" section. I want to create dynamically in my vb.net code, the section "items", to verify if it exists and to know if it has some keys in this order:

Dim config As Configuration = 

Dim items As CustomConfigSection = 

Dim keyItems = ConfigurationManager.AppSettings("Items")
Dim i = 0

for each Section in config.GetSection()

    if Not config.GetSection("Items") then

    end if

    if Not config.AppSettings(Items).Settings.count = 0 then
        config.AppSettings(Items).Settings.Add("Items", myVar)
        for each key in keyItems
            i += 1
            config.AppSettings.Settings.Add("Items" + i, myVar)
    end if

to look like this:

<?xml version="1.0" encoding="utf-8" ?>
    <add key="Items" value="val1"></add>
    <add key="Items1" value="val2"></add>
    <add key="Items2" value="val3"></add>

But I don't know how to manipulate the app.config function and I really don't want to add manually my sections.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.