惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
宝玉的分享
宝玉的分享
月光博客
月光博客
爱范儿
爱范儿
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
阮一峰的网络日志
阮一峰的网络日志
博客园_首页
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
博客园 - 聂微东
小众软件
小众软件
量子位
MongoDB | Blog
MongoDB | Blog
Blog — PlanetScale
Blog — PlanetScale
The Cloudflare Blog
Stack Overflow Blog
Stack Overflow Blog
U
Unit 42
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
H
Help Net Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

博客园 - 我不是冷狐冲,我就是一酒壶

又长草啦 普通HTML的input调用Ext js DatePicker的实现方法 MVC框架下的图表使用(二) MVC框架下的图表使用(一) 关于消息队列的研究 GridView样式及排序问题 新年新开始 WebBrowser控件显示XML流 WebService开发心得 - 我不是冷狐冲,我就是一酒壶 - 博客园 VS 2005 C#操作 XML ASP调用C# DLL - 我不是冷狐冲,我就是一酒壶 - 博客园 Ajax学习笔记 VML图表控件 含吃蛇,加了存档功能了 在cs页取得当前Web页输出的HTML - 我不是冷狐冲,我就是一酒壶 - 博客园 VML学习笔记(本人会不断更新此文章) 长白山游记 贪吃蛇 C# C/S下DataGrid根据数据库里的值(int型)显示ImageList里的图片
VS2005(C#)里读取及改变App.config里appSettings节的值
我不是冷狐冲,我就是一酒壶 · 2007-07-19 · via 博客园 - 我不是冷狐冲,我就是一酒壶

         转眼又是两个月没来了,这段时间比较迷茫,不知道自己应该做什么了?哎,晕了,看看这里,都挂蜘蛛网了,也许我应该和蜘蛛一样,只管织好自己的网就算了,管他织得是什么网,管他织在哪呢!反正我就是蜘蛛,我就织网!!!
         
         前几天做了一个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

    }


}

         希望能对还在C/S战线上坚持不懈的同志们有所帮助,此致敬礼!