editing a config file

  • Thread starter Thread starter bede
  • Start date Start date
B

bede

I have to write a small front end exe which will allow installers to
update a config file. The config file is not part of the project so I
cannot use the sonfiguration namespace but instead update it using
XML.

The config is as follows :
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="ProgramService" connectionString="http://SERVERIP/
WebServices/myservice.asmx" />
</connectionStrings>
<appSettings>
<add key="loggingLevel" value="4" />
</appSettings>
</configuration>

I would like to edit both the "ProgramService" connection string
service and the value of "loggingLevel" in the appsettings but have no
idea where to start.
My XML is pretty poor.
Any ideas ?

Thanks In Advance
 
Something like:

XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlElement el
(XmlElement)doc.SelectSingleNode("/configuration/connectionStrings/add[@name='ProgramService']");
if (el != null)
{ // found
el.SetAttribute("connectionString", "foo");
}
el =
(XmlElement)doc.SelectSingleNode("/configuration/appSettings/add[@key='loggingLevel']");
if (el != null)
{ // found
el.SetAttribute("value", "bar");
}
doc.Save(path);

Marc
 
Back
Top