C#读写app.config中的数据

配置文件内容格式:(app.config)

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
    <add key="DemoKey" value="*" />
</appSettings>
</configuration>

读语句:
          String str = ConfigurationManager.AppSettings["DemoKey"];

写语句:

           Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
           cfa.AppSettings.Settings["DemoKey"].Value = "DemoValue";
           cfa.Save();

 

From: http://gb2013.blog.163.com/blog/static/21735301201021253713453/

posted @ 2011-08-16 17:55  *新*新*  阅读(227)  评论(0编辑  收藏  举报