This code should do:
// use reflection to find the location of the config file
System.Reflecti on.Assembly asm =
System.Reflecti on.Assembly.Get ExecutingAssemb ly ();
System.IO.FileI nfo fi = new System.IO.FileI nfo
(String.Format ("{0}.config ", asm.Location));
if (!fi.Exists)
throw new Exception ("Missing config file");
// load the config file into the XML DOM.
System.Xml.XmlD ocument xmlConfig = new System.Xml.XmlD ocument
();
xmlConfig.Prese rveWhitespace = true;
xmlConfig.Load (fi.FullName);
// find the right node and change it to the new value
foreach (System.Xml.Xml Node node in
xmlConfig["configurat ion"]["appSetting s"])
{
if ((node.Name == "add") &&
(node.Attribute s.GetNamedItem ("key").Valu e ==
"Height"))
{
node.Attributes .GetNamedItem ("value").Va lue =
newHeight;
}
< similar blocks for other parameters >
}
// write out the new config file
xmlConfig.Save (fi.FullName);
Eliyahu
"MK" <mi************ @encorus.com> wrote in message
news:00******** *************** *****@phx.gbl.. .
Is there any way to write into the app config at runtime?
I want to store position, height and width of my forms.