I am asking about editing / deleting or adding sections to web.config I want to be able to add or delete connectionStrings section to my web.config file
here is my web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<connectionStrings />
</configuration>
I used the following code to add the section connectionStrings
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()
I tried to manipulate the code to DELETE the section connectionStrings, but i was not able to do it. I used RemoveChild()
function instead of the AppendChild()
but i get errors like
Error 1 Value of type 'String' cannot be converted to 'System.Xml.XmlNode'.
and
Object reference not set to an instance of an object.
can you help me with my code to delete the section connectionStrings ?