Template diagram
Background code:
Using the XmlDocument method to achieve
private void Serverdialog_load (object sender, EventArgs e)
{
txtserverip.text= configurationmanager.appsettings["Powerserverip"];
Txtport.text = configurationmanager.appsettings["Powerserverport"];
Try
{
ArrayList str = new ArrayList ();
XmlDocument xmldoc = new XmlDocument ();
Xmldoc.load ("WW.exe.config");
XmlNode node = xmldoc.documentelement;
XmlNode appnote = node. selectSingleNode ("appSettings");
XmlNodeList appnotelist = appnote.childnodes;
foreach (XmlNode tmpnote in appnotelist)
{
Str. ADD (tmpnote.attributes["value"]. Value);
}
Txtserverip.text = str[0]. ToString ();
Txtport.text = str[1]. ToString ();
}
catch (Exception ex)
{
MessageBox.Show (ex. Message);
}
}
private void Btnok_click (object sender, EventArgs e)
{
Try
{
ArrayList str = new ArrayList ();
XmlDocument xmldoc = new XmlDocument ();
Xmldoc.load ("WW.exe.config"); Config's name
XmlNode node = xmldoc.documentelement;
XmlNode appnote = node. selectSingleNode ("appSettings");
XmlNodeList appnotelist = appnote.childnodes;
Str. ADD (Txtserverip.text);
Str. ADD (Txtport.text);
Str. Add (FALSE);
Str. Add (FALSE);
Str. Add ("");
int i = 0;
foreach (XmlNode tmpnote in appnotelist)
{
tmpnote.attributes["Value"]. Value = Str[i]. ToString ();
i++;
}
Xmldoc.save (@ "d:\ practice \fun\ww\app.config");
Configurationmanager.refreshsection ("appSettings");
This. Close ();
}
catch (Exception ex)
{
MessageBox.Show (ex. Message);
}
}
WinForm the read and modify of the app. Config XML file