private void button3_Click(object sender, System.EventArgs e)
{
//ConfigurationSettings AppSeting = new ConfigurationSettings();
string filename = textBox1.Text ;
//string section = textBox2.Text ;
string key = textBox3.Text ;
FileStream fs = new FileStream(filename,FileMode.Open);
XmlTextReader xmlreader = new XmlTextReader(fs); string keyValue = System.Configuration.ConfigurationSettings.AppSettings[key].ToString();
if (keyValue != "")
{
Console.WriteLine();
Console.WriteLine("Reading AppSettings");
Console.WriteLine("code_id: " + keyValue);
}
}
为什么说ConfigurationSettings没有引用对象呢...?读取不到配置文件的值?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Name" value="Peter" />
</appSettings>
</configuration>
MessageBox.Show( System.Configuration.ConfigurationSettings.AppSettings["Name"] );
WinForm用App.config(默认是没有的,需要自己加)
<configuration>
<appSettings>
<add key="code_id" keyValue="46000" />
<add key="area_id" keyValue="01000" />
</appSettings>
</configuration>
配置文件如上:文件名称为:myappconfig.config,并且我将该文件和.cs文件放在一起
为winfor
这个试过了。但没有成功