VS2005 如何读写 app.config

VS2005 如何读写 app.config

using System;
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
using System.Collections.Generic;
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
using System.Text;
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
using System.Configuration;
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
using System.Collections;
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
namespace ServicesConfiguration
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追{
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追    
public class ConfigurationDispose
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追    
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追{
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
public ConfigurationDispose()
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追{
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        }

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
GetConfiguration#region GetConfiguration
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
/**//// <summary>
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
/// 取得appSettings里的值
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
/// </summary>
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
/// <param name="key"></param>
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
/// <returns></returns>
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        public static string GetConfiguration(string key)
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追{
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追            
return ConfigurationManager.AppSettings[key];
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        }

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
#endregion

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
GetConfigurationList#region GetConfigurationList
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
/**//// <summary>
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
/// 取得appSettings里的值列表
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
/// </summary>
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
/// <param name="filePath">配置文件路径</param>
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
/// <returns>值列表</returns>
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        public static KeyValueConfigurationCollection GetConfigurationList(string filePath)
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追{
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追            AppSettingsSection appSection 
= null;                       //AppSection对象
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
            Configuration configuration = null;                         //Configuration对象     
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
            KeyValueConfigurationCollection k = null;                   //返回的键值对类型
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追            configuration 
= ConfigurationManager.OpenExeConfiguration(filePath);
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追            
//取得AppSettings节
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
            appSection = (AppSettingsSection)configuration.Sections["appSettings"];
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追            
//取得AppSetting节的键值对
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
            k = appSection.Settings;
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追            
return k;
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追                    
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        }

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
#endregion

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
SetConfiguration#region SetConfiguration
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
/**//// <summary>
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
/// 设置appSetting的值
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
/// </summary>
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
/// <param name="key"></param>
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
/// <param name="value"></param>
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
/// <param name="filePath">App.config文件路径</param>
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        public static void SetConfiguration(string key, string value,string filePath)
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追{
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追            Configuration configuration 
= null;                 //Configuration对象
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
            AppSettingsSection appSection = null;               //AppSection对象 
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
          
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追            configuration 
= ConfigurationManager.OpenExeConfiguration(filePath);
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追            
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追            
//取得AppSetting节
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
            appSection = configuration.AppSettings;
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追            
//赋值并保存
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
            appSection.Settings[key].Value = value;
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追            configuration.Save();
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追            
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        }

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
#endregion

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
SetConfiguration#region SetConfiguration
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
/**//// <summary>
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
/// 设置appSetting的值
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
/// </summary>
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
/// <param name="key"></param>
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
/// <param name="value"></param>
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        public static void SetConfiguration(string key, string value)
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追{
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追            AppSettingsSection appSection 
= null;               //AppSection对象 
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追            appSection 
= ConfigurationManager.GetSection("appSettings");
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追            appSection.Settings[key].Value 
= value;
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        }

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追        
#endregion

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追    }

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追
VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追}

另外一篇是用 XDOC的方法。

关于APP.CONFIG

      在做Winform开发时,免不了把一些配置信息写到APP.CONFIG文件中,当程序生成后APP.CONFIG会变成以程序名+CONFIG的文件

即,如程序名为A,那么生成后的APP.CONFIG文件会变成A.EXE.CONFIG文件!

正文

      以偶在做项目为例.程序要根据用户设定的时间,自动检查OUTLOOK的"垃圾邮件箱"垃圾邮件.!偶把设定后的时间保存在了APP.CONFIG中

用户设定后再重新读取值显示到界面上,用的方法:ConfigurationSettings.AppSettings,结果发现没有读到.后来才明白,原来CONFIG文件只在程序初次运行才读取值.如果在程序运行中,改变其值然后读取,其实读的是缓存的文件.并不是CONFIG文件本身.如果想动态读取就要用XML的读方法

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追/** <summary>

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追/// Read confing

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追/// </summary>

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追/// <param name="path"></param>

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追/// <param name="appKey"></param>

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追/// <returns></returns>

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追public string GetConfigValue(string path,string appKey)  

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追{     

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追  XmlDocument xDoc = new XmlDocument();     

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追  try

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追   VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追{

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追     xDoc.Load(path);     

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追    //xDoc.Load(System.Windows.Forms.Application.ExecutablePath+".config");

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追    XmlNode xNode;     

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追    XmlElement xElem;     

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追    xNode = xDoc.SelectSingleNode("//appSettings");    

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追    xElem = (XmlElement)xNode.SelectSingleNode("//add[@key='"+appKey+"']");     

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追    if(xElem!=null)   

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追     return xElem.GetAttribute("value");     

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追    else     

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追     return   "";

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追   }

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追 catch(Exception)

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追   VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追{

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追     return "";

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追   }

VS2005 如何读写 app.config -  上年纪的程序员  - 有梦就追

我现在的程序中,用的是user Setting的方式,但是 Save后,不会改变 app.exe.config文件,不知道写到哪儿去了,但是程序下次启动时,是有效的,工程太紧,有时间再看看这一块的内容。

还没时间试,弄好了我再贴出来吧。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值