1
構成セクションデザイナー(csd)を使用してアプリケーションにXML構成ファイルを生成しました。csdを使用して生成されたxmlへの読み取り/書き込み
さて、私は(C#の上)このxmlファイルと連携し、2件の観光名所にしたい:
1.は、
txtbox_username.Text = ConfigurationManager.AppSettings["userName"];
のようなものを(その場で検索)特定の値を読みます
2.
は、特定の値、
config.AppSettings.Settings["userName"].Value = txtbox_username.Text;
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("configuration");
-
ような何かを書きます3210
- PS: ...
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
add key="userName" value="Value1"
</appSettings>
</configuration>
が、CSDが、XMLは異なって見える生成:これは私がこのようになり、通常のXMLファイルの読み取り/書き込みを行う方法です
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="sectionName" type="Sample.ConfigurationSection.sectionName, Sample.ConfigurationSection, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</configSections>
<sectionName xmlns="Sample.ConfigurationSection">
<logFile debugLevel="3" filePath="c:\new" maxFileCount="10" maxFileLength="1000"/>
<results path="C:\Results"/>
<details user="blabla" pass="12345" code="abc"/>
<stuff fromAddress="[email protected]" toAddress="[email protected]" sendMail="true""/>
</sectionName>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
ここでは、たとえば、ユーザー/パス/コードフィールドを編集して保存したいとします。
要するに