C#创建Windows服务
ReadyGo!技术成就梦想
网络搜索
efish
2008-8-2 23:35:17
在Windows服务里面,如果访问文件,采用绝对路径可以。如果采用相对路径,和生成的服务文件在同一目录下面。则要访问此程序集 下面的文件。
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Xml;
using System.IO;
namespace HDUSearch
...{
public class IndexConfig
...{
GetValue#region GetValue
public string GetValue(string key)
...{
string assemblyFilePath = Assembly.GetExecutingAssembly().Location;
string assemblyDirPath = Path.GetDirectoryName(assemblyFilePath);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(assemblyDirPath + "\Index.config");
XmlNodeList nodeList = xmlDoc.SelectSingleNode("/configuration/appSettings").ChildNodes; //获取appSettings节点的所有子节点
foreach (XmlNode xn in nodeList) //遍历所有子节点
...{
XmlElement xe = (XmlElement)xn; //将子节点类型转换为XmlElement类型
if (xe.GetAttribute("key").IndexOf(key) != -1)
...{
return xe.GetAttribute("value");
break;
}
}
return "";
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Xml;
using System.IO;
namespace HDUSearch
...{
public class IndexConfig
...{
GetValue#region GetValue
public string GetValue(string key)
...{
string assemblyFilePath = Assembly.GetExecutingAssembly().Location;
string assemblyDirPath = Path.GetDirectoryName(assemblyFilePath);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(assemblyDirPath + "\Index.config");
XmlNodeList nodeList = xmlDoc.SelectSingleNode("/configuration/appSettings").ChildNodes; //获取appSettings节点的所有子节点
foreach (XmlNode xn in nodeList) //遍历所有子节点
...{
XmlElement xe = (XmlElement)xn; //将子节点类型转换为XmlElement类型
if (xe.GetAttribute("key").IndexOf(key) != -1)
...{
return xe.GetAttribute("value");
break;
}
}
return "";
}
#endregion
}
}
-
相关文章
C#数字金额转换大写金额
C#数字金额转换大写金额
c# 启动本机程序
c# 启动本机程序
c# 实现远程关机
c# 实现远程关机
C#创建不规则窗体代码
C#创建不规则窗体代码
如何为程式码加上行号
如何为程式码加上行号
ViewState使用兼谈序列化
ViewState使用兼谈序列化
微软CFO:10亿美元收购雅虎搜索
微软CFO:10亿美元收购雅虎搜索
百度首页添加hao123链接
百度首页添加hao123链接
希捷一年出货硬盘1.83亿块 每秒钟近6块
希捷一年出货硬盘1.83亿块 每秒钟近6块
IT界对云计算的20个定义
IT界对云计算的20个定义
2秒记住本站域名
玩过泡泡龙吗?Readygo?Go! 再加上.Com.Cn的后缀,那就是大名小顶的ReadyGo.com.cn
