this is the code to update the app.config file.
once you modify the app.config file the changes will reflect if you restart the application
you can call the function like this
AppSettingsUpdater.UpdateConfigFile("loginid", "newdetails");
AppSettingsUpdater.UpdateConfigFile("pwd", newdetails2);
your code should be like this
public class AppSettingsUpdater
{
public static void UpdateConfigFile(string key, string value)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
foreach (XmlElement element in xmlDoc.DocumentElement)
if (element.Name == "appSettings")
{
foreach (XmlNode node in element.ChildNodes)
if (node.Attributes[0].Value == key)
node.Attributes[1].Value = value;
}
xmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
ConfigurationManager.RefreshSection("appSettings");
}
}
your app.config file should be like this
="1.0"="utf-8"
<configuration>
<appSettings>
<add key="loginid" value="NODATA"></add>
<add key="pwd" value="NODATA"></add>
</appSettings>
</configuration>