[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

editing a config file

bede

9/15/2008 10:42:00 AM

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
2 Answers

Marc Gravell

9/15/2008 11:05:00 AM

0

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

bede

9/15/2008 1:55:00 PM

0

Thanks Marc

Its much appreciated :-)