VS2005(C#)里读取及改变App.config里appSettings节的值
来源:互联网 发布:徙知徐州的知意思 编辑:程序博客网 时间:2024/05/17 04:17
VS2005(C#)里读取及改变App.config里appSettings节的值
2010-06-01 11:33
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
#region SetConfiguration
/// <summary>
/// 设置appSetting的值
/// </summary>
/// <param name="key">键</param>
/// <param name="value">值</param>
/// <param name="filePath">App.config文件路径</param>
public static void SetConfiguration(string key, string value,string filePath)
{
Configuration configuration = null; //Configuration对象
AppSettingsSection appSection = null; //AppSection对象
configuration = ConfigurationManager.OpenExeConfiguration(filePath);
//取得AppSetting节
appSection = configuration.AppSettings;
//赋值并保存
appSection.Settings[key].Value = value;
configuration.Save();
}
#endregion
#region SetConfiguration
/// <summary>
/// 设置appSetting的值
/// </summary>
/// <param name="key">键</param>
/// <param name="value">值</param>
public static void SetConfiguration(string key, string value)
{
AppSettingsSection appSection = null; //AppSection对象
appSection = ConfigurationManager.GetSection("appSettings");
appSection.Settings[key].Value = value;
}
#endregion
}
}
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
#region SetConfiguration
/// <summary>
/// 设置appSetting的值
/// </summary>
/// <param name="key">键</param>
/// <param name="value">值</param>
/// <param name="filePath">App.config文件路径</param>
public static void SetConfiguration(string key, string value,string filePath)
{
Configuration configuration = null; //Configuration对象
AppSettingsSection appSection = null; //AppSection对象
configuration = ConfigurationManager.OpenExeConfiguration(filePath);
//取得AppSetting节
appSection = configuration.AppSettings;
//赋值并保存
appSection.Settings[key].Value = value;
configuration.Save();
}
#endregion
#region SetConfiguration
/// <summary>
/// 设置appSetting的值
/// </summary>
/// <param name="key">键</param>
/// <param name="value">值</param>
public static void SetConfiguration(string key, string value)
{
AppSettingsSection appSection = null; //AppSection对象
appSection = ConfigurationManager.GetSection("appSettings");
appSection.Settings[key].Value = value;
}
#endregion
}
}
- VS2005(C#)里读取及改变App.config里appSettings节的值
- VS2005(C#)里读取及改变App.config里appSettings节的值
- VS2008(C#)里读取及改变App.config里appSettings节的值
- 关于C#和ASP.NET中对App.config和Web.config文件里的[appSettings]和[connectionStrings]节点进行新增、修改、删除和读取相关的操作
- 关于C#和ASP.NET中对App.config和Web.config文件里的[appSettings]和[connectionStrings]节点进行新增、修改、删除和读取相关的操作
- C# 读取和设置app.config里的connectionstring
- C# 读取和设置app.config里的connectionstring
- App.config 两种版本读取方式(appSettings 和 applicationSettings 的区别)
- .NET工程读取web.config或app.config中的appsettings时的注意事项
- 读取web.config中appSettings的key值
- 点滴积累: app.config里的配置节
- 更改App.config里的值并保存
- 在winform中使用程序读取和修改App.config里面的appSettings当中的Value值
- 在winform中使用程序读取和修改App.config里面的appSettings当中的Value值
- asp.net读取Web.config的<appSettings></appSettings>
- app.config配置文件的connectionStrings和appSettings
- Asp.NET Core 在Controller调用appsettings里的值
- DotNetCore跨平台~关于appsettings.json里各种配置项的读取
- 深入Java中文编码乱码问题及最优解决方法
- uva 11402 ahoy pirates
- lucene的多个字段搜索以及分页并高亮显示
- [Linux学习笔记]VirtualBox安装CentOS
- 更改内核的启动画面
- VS2005(C#)里读取及改变App.config里appSettings节的值
- std string 的常用使用
- linux上更改TCP窗口大小
- vs快捷键大全(转)
- httpclient 调用
- weblogic中oracle jdbc驱动更新方法
- pageEncoding contentType区别
- Onscripter for Android 04.25 更新!
- 十年混个技术总监