您现在的位置: 天下网吧 >> 网吧天地 >> 天下码农 >> 微信小程序 >> 正文

C#创建Windows服务

2008-11-6来自网络佚名
   在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
}
}

欢迎访问最专业的网吧论坛,无盘论坛,网吧经营,网咖管理,网吧专业论坛 https://bbs.txwb.com

关注天下网吧微信/下载天下网吧APP/天下网吧小程序,一起来超精彩

本文来源:来自网络 作者:佚名

声明
声明:本站所发表的文章、评论及图片仅代表作者本人观点,与本站立场无关。若文章侵犯了您的相关权益,请及时与我们联系,我们会及时处理,感谢您对本站的支持!联系邮箱:support@txwb.com,系统开号,技术支持,服务联系QQ:1175525021本站所有有注明来源为天下网吧或天下网吧论坛的原创作品,各位转载时请注明来源链接!
天下网吧 网吧天下