テキストボックスでユーザーから指定された値を、XMlファイルのTestModeの値として使用したいと思います。XMLファイルは次のようになります。
<appSettings>
<add key="SaveWindowItemsMap" value="true"/>
<add key="TestMode" value=""/>
</appSettings>
値は、実行時にユーザー(テキストボックス内)から指定されたとおりに渡されるため、XMLファイルで更新しないでください。
これを試すことができますか:
アプリケーション設定値を変更するコード サンプルを次に示します。
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
foreach (XmlElement element in xmlDoc.DocumentElement)
{
if (element.Name.Equals("appSettings"))
{
foreach (XmlNode node in element.ChildNodes)
{
if (node.Attributes[0].Value.Equals("SaveWindowItemsMap"))
{
node.Attributes[1].Value = "New Value";
}
}
}
}
xmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
ConfigurationManager.RefreshSection("appSettings");
「SaveWindowItemsMap」値を更新したいと想定しています。