Updating a DictionarySectionHandler in web config programmatically   

When trying to modify section in the web config that is using a non-trivial type the only method that seems be available is SetRawXml. SetRawXml, as the name clearly states will update the entire element. Therefore we need to include the element tags as well as the information Here is a sample on how to update a DictionarySectionHandler
 

 Code Snippet

Configuration myconfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null);

ConfigurationSection section = myconfig.GetSection(sectionName);

string rawXML = String.Format("<{0}>", section.SectionInformation.Name);

foreach (KeyValuePair kv in dic)
{
    rawXML = rawXML + String.Format("", kv.Key, kv.Value);
}

rawXML = rawXML + String.Format("", section.SectionInformation.Name);

section.SectionInformation.SetRawXml(rawXML);

myconfig.Save();
Published  on  4/1/2009  by  xsolon
0  Comments  |  Trackback Url  | 0  Links to this post | Bookmark this post with:          
Tags: | Categories:
Technorati Tags:
 

Links to this post

Comments

Title:
Receieve Notification:
Website:
Email:
Comments:

CAPTCHA Image Validation