在Windows服务里面
如果访问文件
采用绝对路径可以
如果采用相对路径
和生成的服务文件在同一目录下面
则要访问此程序集 下面的文件
using System;
using SystemCollectionsGeneric;
using SystemText;
using SystemReflection;
using SystemXml;
using SystemIO;
namespace HDUSearch
…{
public class IndexConfig
…{
GetValue#region GetValue
public string GetValue(string key)
…{
string assemblyFilePath = AssemblyGetExecutingAssembly()Location;
string assemblyDirPath = PathGetDirectoryName(assemblyFilePath)
XmlDocument xmlDoc = new XmlDocument()
xmlDocLoad(assemblyDirPath + \nfig)
XmlNodeList nodeList = xmlDocSelectSingleNode(/configuration/appSettings)ChildNodes; //获取appSettings节点的所有子节点
foreach (XmlNode xn in nodeList) //遍历所有子节点
…{
XmlElement xe = (XmlElement)xn; //将子节点类型转换为XmlElement类型
if (xeGetAttribute(key)IndexOf(key) != )
…{
return xeGetAttribute(value)
break;
}
}
return ;
}
#endregion
}
}