UP,能行么?要不用INI文件也行的
解决方案 »
- 用C#做个事物提醒,像现在360的健康精灵那样的,不知道大家有没用过。
- 窗体刷新问题
- 拆箱问题
- windows server2003现在有没有终端用户时间有没有不限制的?
- 请问:如何改变winform的标题栏的颜色背景?
- ++++++++简单问题高手请来,如何把.cs类做成dll,调用????+++++++
- Decimal 格式化如何去掉尾部的0?
- 怎样取得系统默认的languageID,急,急,急!!!!
- 在c#里面怎么样编写OCX呢?
- 一个莫名其妙的错误!高手请进
- 请教:Bitmap 构造函数 (Type, String) 从指定的资源初始化 Bitmap 类的新实例?
- 请教如何实现可以自动完成的编辑控件,就像IE里面使用cookies的一样?
现在读取的方法很简单,但是如何修改呢?
还有,在运行的时候,可以修改通过应用程序本身修改应用程序的config文件吗?
{ /// 修改指定config文件appSettings配置节中的Add里的value属性
/// </summary>
/// <res>
/// 注意,调用该函数后,会使整个Web Application重启,导致当前所有的会话丢失
/// </res>
/// <param name="key">要修改的键key</param>
/// <param name="strValue">修改后的value</param>
/// <exception cref="">找不到相关的键</exception>
/// <exception cref="">权限不够,无法保存到web.config文件中</exception>
///
string XPath="/configuration/appSettings/add[@key='?']";
XmlDocument domWebConfig=new XmlDocument();
domWebConfig.Load( (HttpContext.Current.Server.MapPath(ConfigFileName)) );
XmlNode addKey=domWebConfig.SelectSingleNode( (XPath.Replace("?",strKey)) );
if(addKey == null)
{//如果没找到,就新加一条
this.InsertConfigSet(ConfigFileName,strKey,strValue);
return;
}
addKey.Attributes["value"].InnerText=strValue;
domWebConfig.Save( (HttpContext.Current.Server.MapPath(ConfigFileName)) );
}
public void InsertConfigSet(string ConfigFileName,string strKey,string strValue)
{ //向指定config文件中插入节点和设置值
string XPath="/configuration/appSettings";
XmlDocument domWebConfig=new XmlDocument(); domWebConfig.Load( (HttpContext.Current.Server.MapPath(ConfigFileName)) );
XmlNode appSettings=domWebConfig.SelectSingleNode( XPath );
XmlNode add= domWebConfig.CreateNode(XmlNodeType.Element,"add",""); XmlAttribute key=domWebConfig.CreateAttribute("key");
key.Value=strKey;
XmlAttribute Value=domWebConfig.CreateAttribute("value");
Value.Value=strValue; add.Attributes.Append(key);
add.Attributes.Append(Value); appSettings.AppendChild(add); domWebConfig.Save( (HttpContext.Current.Server.MapPath(ConfigFileName)) );
}