关于System.configuration的保存问题

dahaig 2006-12-06 10:44:01
现象:
msdn的例子都是保存到addlication的debug目录下的*.vshost.exe.config这个xml文件中,但是每次程序关闭后,就把运行时写入的值丢弃了,变成了app.config中的值了
问题:
怎么样才能使用System.configuration,保存数据到配置文件,在程序关闭后也能保存下来呢?
...全文
296 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
marvelstack 2006-12-19
  • 打赏
  • 举报
回复
你在使用vs启动程序调试的时候,会复制项目中的app.config到debug目录,把原来的<程序名>.exe.config文件覆盖掉,建议在程序调试结束的时候,打开<程序名>.exe.config文件看看是否有保存成功。还有一种情况是你填写的app.config节点的文件路径是否有问题,他是区分大小写的。
dahaig 2006-12-13
  • 打赏
  • 举报
回复
再顶一下
liujia_0421 2006-12-07
  • 打赏
  • 举报
回复
关注一下..
zhaochong12 2006-12-07
  • 打赏
  • 举报
回复
o_o... 不明白....

能不能自己建立一个xml保存状态, 结束的时候替换掉app.config
bigrongshu 2006-12-07
  • 打赏
  • 举报
回复
1 *.exe.config 是app.config的拷贝,是在rebuild时候做的,也就是说,build是不会覆盖你原先保存的*.exe.config

2 如何写 *.exe.config?
只能用手工write xml文件的方法

private bool UpdateConnectionStrConfig(string Xvalue)
{
XmlDocument doc = new XmlDocument();
doc.Load(Application.ExecutablePath + ".config");

XmlNode node = doc.SelectSingleNode(@"//add[@name='SqlServices']");
XmlElement ele = (XmlElement)node;
if (ele != null)
{
ele.SetAttribute("connectionString", Xvalue);
doc.Save(Application.ExecutablePath + ".config");

return true;
}
else return false;

}
dahaig 2006-12-07
  • 打赏
  • 举报
回复
up and waiting……
dahaig 2006-12-07
  • 打赏
  • 举报
回复
继续关注
scow 2006-12-07
  • 打赏
  • 举报
回复
没有写, 只有读. 因为没必要写.
feifeiyaqi3 2006-12-07
  • 打赏
  • 举报
回复
不遇到过
dahaig 2006-12-07
  • 打赏
  • 举报
回复
如果写app.config,那还要System.Configuration干什么啊
我觉得这个办法不对
还是我没有用好System.Configuration
continue waiting……

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧