title: ADD and DELETE section in web.config
body: <p>I am asking about editing / deleting or adding sections to web.config
  I want to be able to add or delete <strong>connectionStrings</strong> section to my web.config file </p>
  
  <p>here is my web.config</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.0" /&gt;
    &lt;/system.web&gt;
    &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true" /&gt;
     &lt;/system.webServer&gt;
  &lt;connectionStrings /&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I used the following code to add the section <strong>connectionStrings</strong></p>
  
  <pre><code> Dim doc As XmlDocument = New XmlDocument()
   Dim path As String = Server.MapPath("~/Web.Config")
   doc.Load(path)
   Dim newElem As XmlElement = doc.CreateElement("connectionStrings")
   doc.DocumentElement.AppendChild(newElem)
   doc.PreserveWhitespace = False
   Dim wrtr As XmlTextWriter = New XmlTextWriter(path, Encoding.Unicode)
   doc.WriteTo(wrtr)
   wrtr.Close()
  </code></pre>
  
  <p>I tried to manipulate the code to DELETE the section <strong>connectionStrings</strong>, but i was not able to do it. I used <code>RemoveChild()</code> function instead of the <code>AppendChild()</code> but i get errors like </p>
  
  <pre><code>Error 1 Value of type 'String' cannot be converted to 'System.Xml.XmlNode'. 
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Object reference not set to an instance of an object.
  </code></pre>
  
  <p>can you help me with my code to delete the section <strong>connectionStrings</strong> ?</p>