资源描述
VS2005(C#)里读取及改变Appconfig里appSettings节的值.txt21春暖花会开!如果你曾经 历过冬天,那么你就会有春色!如果你有着信念,那么春天一定会遥远;如果你正在付出, 那么总有一天你会拥有花开满圆。VS2005 (C#)里读取及改变App.config里appSettings 节的值 标签: App.config 2011-01-30 10:48using System;using System.Collections.Generic;using System.Text;using System.Configuration;using System.Collections;namespace ServicesConfigurationpublic class ConfigurationDisposepublic ConfigurationDispose()#region GetConfiguration/ / 取得 appSettings 里的值/ / param name二key键/param/ returns值/returnspublic static string GetConfiguration(string key)return ConfigurationManager.AppSettingskey;#endregion#region GetConfigurationList/ summary/ 取得 appSettings 里的值列表/ /summary/param name二filePa th配置文件路径/param/ re tu rns值列表/re tu rnspublic static KeyValueConfigurationCollectionGetConfigurationList(string filePath)AppSettingsSectionappSection=null;/AppSec tion 对象Configurationconfiguration=null;/Configura tion 对象KeyValueConfigurationCollection k = null;/返回的键值对类型configuration = ConfigurationManager.OpenExeConfiguration(filePath);/取得 AppSettings 节 appSection = (AppSettingsSection)configuration.SectionsappSettings;/取得 AppSetting 节的键值对k = appSection.Settings;return k;#endregion#region SetConfiguration/ / 设置 appSetting 的值/ / param name二key键/param/ param name二value值/param/param name二filePa thApp.config 文件路径/parampublic static void SetConfiguration(string key, string value,string filePath)Configuration configuration = null;/Configuration对象AppSe tti ngsSec tion appSec tion 二 null;/AppSec tior对象configuration = ConfigurationManager.OpenExeConfiguration(filePath);/取得 AppSetting 节appSection = configuration.AppSettings;/赋值并保存appSection.Settingskey.Value = value; configuration.Save();#endregion #region SetConfiguration/ / 设置 appSetting 的值/ / param name二key键/param/ param name二value值/parampublic static void SetConfiguration(string key, string value) AppSe tti ngsSec tion appSec tion 二 null;/AppSec tior对象appSection = ConfigurationManager.GetSection(appSettings);appSection.Settingskey.Value = value;#endregion
展开阅读全文