Windows程序控件属性与配置文件的<appSettings>节中的值映射问题 将windows应用程序配置文件的<appSettings>节中的值映射到控件的属性,在控件属性更改后,怎么保存到配置文件中啊?我以前用修改XML文件保存,这样太啰唆了,有没有更好的办法? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用这个类:using System;using System.Xml;using System.Windows.Forms;namespace Common{ /// <summary> /// 模块名称: 读写系统配置类 /// 编写日期: 2005-12-01 /// </summary> public class AppConfig { public static bool UpdateConfig(string strKey, string strValue) { XmlDocument doc = new XmlDocument(); try { doc.Load(Application.ExecutablePath + ".config"); XmlNode node = doc.SelectSingleNode(@"//add[@key='" + strKey + "']"); XmlElement ele = (XmlElement)node; ele.SetAttribute("value", strValue); doc.Save(Application.ExecutablePath + ".config"); } catch { return false; } return true; } public AppConfig() { // // TODO: 在此处添加构造函数逻辑 // } public static string GetConfig(string strKey) { //return System.Configuration.ConfigurationManager.AppSettings[strKey]; XmlDocument doc = new XmlDocument(); try { doc.Load(Application.ExecutablePath + ".config"); XmlNode node = doc.SelectSingleNode(@"//add[@key='" + strKey + "']"); XmlElement ele = (XmlElement)node; return ele.GetAttribute("value"); } catch { return string.Empty; } } }} windows有这样的应用程序配置文件吗?学习一下... 呵呵,VS2005中有,文件名叫App.Config,安装后文件会生成一个名叫:应用程序名.exe.Config的XML文件。 哦,你要添加一个啊,在添加对话框中选择应用程序配置文件,使用嘛,跟web.config差不多啊,可以用System.Configuration.ConfigurationManager.AppSettings["..."]来获取。 多谢:)Snowdust(雪尘) ( ) 信誉:100 Blog app.config有个问题:在运行时修改<appSettings>节点值,然活再用System.Configuration.ConfigurationSettings.AppSettings["key"]获取值,结果还是未修改前的值 那是当然的,要重启应用程序才能取得更改后的值。所以动态改app.config没啥意义,如果要看到即时的修改结果,可以用注册表存配置信息。 如果是2003,本质上还是需要通过修改app.config的方式来处理,如果是2005,增加了Settings.setting设置文件,可以对用户级别的配置文件进行直接修改。http://www.microsoft.com/china/msdn/library/langtool/vcsharp/SettingsCSRL.mspx?mfr=true c# 中怎么获取 字节二进制的高位低位 并且取反之类的. 没学过C啊 吐血 c# 实现局域网断点续传 我想学用C#做一个windows服务,谁能给一个简单明了的可执行代码例子,谢谢 C#中使用FarPoint Spread 控件查找定位的问题 问一个程序打包的问题 C# 调用delphi动态库 高手指教! 有看过易学C#这本书的朋友请进 关于迭代的问题 ado.net问题 在C#中怎样根据控件名如(TextBox1)转为TextBox类型后使用,而不是仅判断有没有这个控件。 怎样将文本文件里的一部分行删除掉,利用StreamReader怎么实现。。急啊... ADO.NET菜问。
using System;
using System.Xml;
using System.Windows.Forms;namespace Common
{
/// <summary>
/// 模块名称: 读写系统配置类
/// 编写日期: 2005-12-01
/// </summary>
public class AppConfig
{
public static bool UpdateConfig(string strKey, string strValue)
{
XmlDocument doc = new XmlDocument();
try
{
doc.Load(Application.ExecutablePath + ".config");
XmlNode node = doc.SelectSingleNode(@"//add[@key='" + strKey + "']");
XmlElement ele = (XmlElement)node;
ele.SetAttribute("value", strValue);
doc.Save(Application.ExecutablePath + ".config");
}
catch
{
return false;
}
return true;
}
public AppConfig()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static string GetConfig(string strKey)
{
//return System.Configuration.ConfigurationManager.AppSettings[strKey];
XmlDocument doc = new XmlDocument();
try
{
doc.Load(Application.ExecutablePath + ".config");
XmlNode node = doc.SelectSingleNode(@"//add[@key='" + strKey + "']");
XmlElement ele = (XmlElement)node;
return ele.GetAttribute("value");
}
catch
{
return string.Empty;
}
}
}
}
学习一下...
Snowdust(雪尘) ( ) 信誉:100 Blog
在运行时修改<appSettings>节点值,然活再用
System.Configuration.ConfigurationSettings.AppSettings["key"]获取值,
结果还是未修改前的值
增加了Settings.setting设置文件,可以对用户级别的配置文件进行直接修改。
http://www.microsoft.com/china/msdn/library/langtool/vcsharp/SettingsCSRL.mspx?mfr=true