.net framework 2.0以上修改config配制更容易


    读APPSETTING行简单:
 _nowVersion = ConfigurationManager.AppSettings["nowVersion"];

    以前与配制通过操作XML文件来进行,现在可以修改为以下方式:

 ExeConfigurationFileMap filemap = new ExeConfigurationFileMap();
            filemap.ExeConfigFilename 
= "AupdateConsole.exe.config";
            Configuration config 
= ConfigurationManager.OpenMappedExeConfiguration(filemap, ConfigurationUserLevel.None);

            config.AppSettings.Settings[
"nowVersion"].Value = _nowVersion;
            config.AppSettings.Settings[
"siteCode"].Value = _siteCode;
            config.AppSettings.Settings[
"siteName"].Value = _siteName;
            config.AppSettings.Settings[
"appId"].Value = _appId;
            config.AppSettings.Settings[
"appCode"].Value = _appCode;
            config.Save();
            
return true;
posted on 2008-01-08 09:52  edobnet  阅读(794)  评论(0编辑  收藏  举报