VS2005(C#)里读取及改变App.config里appSettings节的值
来源:互联网 发布:mysql msvcp120.dll 编辑:程序博客网 时间:2024/04/29 21:16
http://www.cnblogs.com/cstded/archive/2007/07/19/823950.html
转眼又是两个月没来了,这段时间比较迷茫,不知道自己应该做什么了?哎,晕了,看看这里,都挂蜘蛛网了,也许我应该和蜘蛛一样,只管织好自己的网就算了,管他织得是什么网,管他织在哪呢!反正我就是蜘蛛,我就织网!!!
前几天做了一个C/S的项目,研究了一下App.config,写了一个读取及改变App.config里appSettings节的值的类,贴出来!
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
}
}
0 0
- 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里各种配置项的读取
- 数据结构——栈
- OOP 原则
- Android调用webservice示例教程
- Oracle中删除某个用户下的所有数据呢
- IOS 构造和使用TableView(基于storyboard) (一)基本的数据显示
- VS2005(C#)里读取及改变App.config里appSettings节的值
- android 学习: 背景滚动效果
- LCD的接口类型详解
- visual studio 自动排版快捷键
- JAVA的字符串拼接与性能
- TS
- Myeclipse8.5中svn插件安装方法总结
- 《黑马程序员》 使用阻塞队列实现同步通知
- FLV