如何读写 app.config
2009-09-04 15:36
267 查看
如何读写 app.config
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Collections;
namespace ServicesConfiguration
{
public class ConfigurationDispose
{
public ConfigurationDispose()
{
}
#region GetConfiguration
/// <summary>
/// 取得appSettings里的值
/// </summary>
/// <param name="key">键</param>
/// <returns>值</returns>
public static string GetConfiguration(string key)
{
return ConfigurationManager.AppSettings[key];
}
#endregion
#region GetConfigurationList
/// <summary>
/// 取得appSettings里的值列表
/// </summary>
/// <param name="filePath">配置文件路径</param>
/// <returns>值列表</returns>
public static KeyValueConfigurationCollection GetConfigurationList(string filePath)
{
AppSettingsSection appSection = null; //AppSection对象
Configuration configuration = null; //Configuration对象
KeyValueConfigurationCollection k = null; //返回的键值对类型
configuration = ConfigurationManager.OpenExeConfiguration(filePath);
//取得AppSettings节
appSection = (AppSettingsSection)configuration.Sections["appSettings"];
//取得AppSetting节的键值对
k = appSection.Settings;
return k;
}
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Collections;
namespace ServicesConfiguration
{
public class ConfigurationDispose
{
public ConfigurationDispose()
{
}
#region GetConfiguration
/// <summary>
/// 取得appSettings里的值
/// </summary>
/// <param name="key">键</param>
/// <returns>值</returns>
public static string GetConfiguration(string key)
{
return ConfigurationManager.AppSettings[key];
}
#endregion
#region GetConfigurationList
/// <summary>
/// 取得appSettings里的值列表
/// </summary>
/// <param name="filePath">配置文件路径</param>
/// <returns>值列表</returns>
public static KeyValueConfigurationCollection GetConfigurationList(string filePath)
{
AppSettingsSection appSection = null; //AppSection对象
Configuration configuration = null; //Configuration对象
KeyValueConfigurationCollection k = null; //返回的键值对类型
configuration = ConfigurationManager.OpenExeConfiguration(filePath);
//取得AppSettings节
appSection = (AppSettingsSection)configuration.Sections["appSettings"];
//取得AppSetting节的键值对
k = appSection.Settings;
return k;
}
#endregion
相关文章推荐
- 如何读写 app.config 2
- VS2005 如何读写 app.config
- C#读写app.config中的数据
- .net类库获取当前类库的配置(dll的app.config读写)
- 用.NET 2.0 Enterprise Library库读写App.config文件(3)
- Android app如何正确读写系统sys设备节点
- C#读写app.config中的数据(收藏)
- App.Config详解及读写操作
- App.Config详解及读写操作
- app.config的读写、更新问题 两篇链接
- .NET 2.0中,配置文件app.config的读写(VS2005,C#)
- Forward:使用.NET 2.0读写App.config
- WPF中读写app.config操作
- .net下读写配置文件app.config方法
- App.config 中读写appSettings、system.serviceModel终结点,以及自定义配置节
- App.Config详解及读写操作
- C#读写app.config中的数据
- c# 读写app.config
- Winform读写App.config文件以及重启程序
- App.Config详解及读写操作