现在的位置: 首页 > 综合 > 正文

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

2011年08月24日 ⁄ 综合 ⁄ 共 763字 ⁄ 字号 评论关闭
    读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;

抱歉!评论已关闭.