📄 webconfigtool.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Web;
namespace MemberServerBLL
{
public class WebConfigTool
{
public static void SetValue(string key, string strValue, string FileName)
{
string XPath = "/appSettings/add[@key='?']";
XmlDocument membershipConfig = new XmlDocument();
membershipConfig.Load((HttpContext.Current.Server.MapPath(FileName)));
XmlNode addKey = membershipConfig.SelectSingleNode((XPath.Replace("?", key)));
if (addKey == null)
{
throw new ArgumentException("没有找到<add key='" + key + "' value=.../>的配置节");
}
addKey.Attributes["value"].InnerText = strValue;
membershipConfig.Save((HttpContext.Current.Server.MapPath(FileName)));
}
public static string GetValue(string key, string FileName)
{
string XPath = "/appSettings/add[@key='?']";
XmlDocument membershipConfig = new XmlDocument();
membershipConfig.Load((HttpContext.Current.Server.MapPath(FileName)));
XmlNode addKey = membershipConfig.SelectSingleNode((XPath.Replace("?", key)));
if (addKey == null)
{
throw new ArgumentException("没有找到<add key='" + key + "' value=.../>的配置节");
}
return addKey.Attributes["value"].InnerText;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -