我先对App.config中的value进行了修改并且成功了,然后在用ConfigurationManager.AppSettings.Get(key);方法来查结果得到的还是和开始没有修改一样,问一下这是怎么回事啊,我也用了 ConfigurationManager.RefreshSection("appSettings");也不行,这是怎么回事呢?
解决方案 »
- C# 中有没有seek getfileposition 的流
- (求教)关于如何更改键盘实际发送值的问题
- c#生成透明背景图问题,有点急!
- C#中用SaveFileDialog类保存文件,如何另外增加字符编码(ANSI、UTF-8等)选项
- 100分赠送:请问有没有办法从pdf文件中提取文本内容~~
- 急救,Web服务中返回SqlDataReader的值出错,跪求高手帮忙!
- 如何将已经得到的dataset插入到一张临时表,即利用已有的dataset在sql server2000中生成一张临时表?急求实例!!!
- 请问:怎样在c#中使用vc++编写的封装在Dll中的类? 急 谢谢
- 谁有用程序调DTS的例子,最好是C#的,其它也行:P
- 什么是C#
- 怎么删除约束啊,
- 求教如何控制datagridview控件的鼠标滚动行数
ConfigurationManager.RefreshSection("appSettings")
sValue = ConfigurationManager.AppSettings(name)
http://stackoverflow.com/questions/590791/do-you-have-to-restart-a-windows-service-if-you-change-the-app-config/
所以不用担心你所说的。
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="strValue"></param>
public void Modify(string key, string strValue) //两个参数:要修改的键值 和 要修改的新值;
{
string flagstr = strValue;
if (strValue == string.Empty)
{
MessageBox.Show("连接串不能为空!");
return;
}
try
{
string XPath = "/configuration/appSettings/add[@key='?']";
XmlDocument domWebConfig = new XmlDocument(); domWebConfig.Load(filepath);
XmlNode addKey = domWebConfig.SelectSingleNode((XPath.Replace("?", key))); if (addKey == null)
{
MessageBox.Show("没有找到<add key='" + key + "'>的配置节");
return;
}
addKey.Attributes["value"].InnerText = strValue;
domWebConfig.Save(filepath);
MessageBox.Show("数据库连接配置成功","信息提示");
}
catch
{
return;
} }
类似这样的代码,
filepath =Application.StartupPath;
filepath += "//App.config";