Results 1 to 6 of 6

Thread: Adding a new entry in the config in code

Threaded View

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Adding a new entry in the config in code

    I have the following code which takes in a string representing an element in my settings/config file. It then returns the value of that element.

    Code:
    public string GetAppConfigValue(string SettingName)
    {
                string sContents;
                ConfigurationSectionGroup grpApp = config.GetSectionGroup("applicationSettings");
                ClientSettingsSection secPropSet = (ClientSettingsSection)grpApp.Sections[sSettingsSection];
                secPropSet.SectionInformation.ForceSave = true;
                SettingElement elm = secPropSet.Settings.Get(SettingName);
                if (elm == null)
                {
                    sContents = SettingName + " is missing!";
                }
                else
                {
                    sContents = elm.Value.ValueXml.InnerText.Trim();
                }
                return sContents;
    }
    This all works fine but what I need to do is create this setting with a string "NOT AVAILABLE"if it is not there.

    I think its something along the lines off :
    Code:
    SettingElement newElem = new SettingElement(SettingName, SettingsSerializeAs.String);
    secPropSet.Settings.Add(newElem);
    //How do i add "NOT AVAILABLE" to its value
    The above code adds this to the config "<setting name="NEW_ATTRIBUTE" serializeAs="String" />" but it has no value and no closing tag " </setting>"
    Man am I ever confused :-(
    Last edited by venerable bede; Aug 5th, 2008 at 11:16 AM.

    Parksie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width