wpf app.config 客户端进行配置和修改.
来源:互联网 发布:大数据为什么在贵阳 编辑:程序博客网 时间:2024/04/30 19:29
public class ConfigSettings
{
private static string NodePath = "//system.serviceModel//client//endpoint";
private ConfigSettings() { }
public static string GetEndpointAddress()
{
return ConfigSettings.loadConfigDocument().SelectSingleNode(NodePath).Attributes["address"].Value;
}
public static string GetAddressForMap()
{
XmlDocument doc = loadConfigDocument();
XmlNode appSettingsNode = doc.SelectSingleNode("configuration/appSettings");
string value="";
foreach (XmlNode childNode in appSettingsNode)
{
if (childNode.Attributes==null)continue ;
if (childNode.Attributes["key"] !=null && childNode.Attributes["key"].Value == "mapurl")
{
value= childNode.Attributes["value"].Value;
break;
}
}
return value;
}
public bool KeyExists(string strKey)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(AppDomain.CurrentDomain.BaseDirectory + "..\\..\\App.config");
XmlNode appSettingsNode = xmlDoc.SelectSingleNode("configuration/appSettings");
foreach (XmlNode childNode in appSettingsNode)
{
if (childNode.Attributes["key"].Value == strKey)
return true;
}
return false;
}
public static void SaveEndpointAddress(string endpointAddress, string mapurl)
{ // load config document for current assembly
XmlDocument doc = loadConfigDocument();
// retrieve appSettings node
XmlNode node = doc.SelectSingleNode(NodePath);
if (node == null)
throw new InvalidOperationException("Error. Could not find endpoint node in config file.");
try
{ // select the 'add' element that contains the key
//XmlElement elem = (XmlElement)node.SelectSingleNode(string.Format("//add[@key='{0}']", key));
node.Attributes["address"].Value = endpointAddress;
XmlNode appSettingsNode = doc.SelectSingleNode("configuration/appSettings");
foreach (XmlNode childNode in appSettingsNode)
{
if (childNode.Attributes == null) continue;
if (childNode.Attributes["key"] != null && childNode.Attributes["key"].Value == "mapurl")
{
childNode.Attributes["value"].Value = mapurl;
}
}
doc.Save(getConfigFilePath());
}
catch (Exception e)
{ throw e; }
}
public static XmlDocument loadConfigDocument()
{
XmlDocument doc = null;
try
{
doc = new XmlDocument();
doc.Load(getConfigFilePath());
return doc;
}
catch (System.IO.FileNotFoundException e)
{
throw new Exception("No configuration file found.", e);
}
}
private static string getConfigFilePath()
{
return Assembly.GetExecutingAssembly().Location + ".config";
}
}
- wpf app.config 客户端进行配置和修改.
- 修改app.config 节点配置
- 动态修改App.Config 和web.Config
- 动态修改App.Config 和web.Config
- 关于C#和ASP.NET中对App.config和Web.config文件里的[appSettings]和[connectionStrings]节点进行新增、修改、删除和读取相关的操作
- 关于C#和ASP.NET中对App.config和Web.config文件里的[appSettings]和[connectionStrings]节点进行新增、修改、删除和读取相关的操作
- app.config进行加密
- app.config修改操作
- 修改APP.config文件
- 修改app.config
- 修改App.config文件
- wpf config配置文件的修改
- C#配置App.config
- App.config配置
- C#配置App.config
- C#配置App.config
- C#配置app.config
- C#配置App.config
- ubuntu之scim输入法的安装
- sitemesh 项目中的使用
- ORACLE SQL Loader的详细语法
- setjmp和longjmp的"非本地跳转"
- 记录一些好文章.
- wpf app.config 客户端进行配置和修改.
- j2me图片转换为二进制的解决办法?
- 深刻理解Linux进程间通信(IPC)
- RAC架构之业务分割
- delphi 中实现当期日期 减去 若干小时的方法
- spring中的Bean配置注意的地方
- Solaris quota命令
- uvaoj 488 - Triangle Wave
- 用汇编编写DOS下的内存驻留程序