U9 DLL读取配制文件

 

在网上大多数的例子都是如何访问程序运行的目录下的配制文件,可是U9BP里要将DLL放到生产环境,我并不知道生产环境运行的目录,因此只能DLL读取当前目录XML。函数

过下面几个方法均可以拿到程序所在的文件夹或程序文件网站

  • AppDomain.CurrentDomain.BaseDirectory 当前程序域寻找 dll 的文件夹
  • Environment.CurrentDirectory 当前工做文件夹
  • Assembly.GetCallingAssembly().Location 调用当前函数的函数的程序集的文件
  • Assembly.GetEntryAssembly().Location 入口函数程序集所在的文件
  • Assembly.GetExecutingAssembly().Location 包含当前代码的程序集的文件
  • Directory.GetCurrentDirectory 当前工做文件夹

因此我固然选第一种 AppDomain.CurrentDomain.BaseDirectoryurl

XML文件

<?xml version="1.0" encoding="utf-8" ?> <Configure> <portConfigure> <url></url> <tokenUrl></tokenUrl> <user></user> <password></password> </portConfigure> </Configure>

 

//读取网站下XML文件CS代码
string
path = AppDomain.CurrentDomain.BaseDirectory+"XXX.xml"; XmlDocument xml = new XmlDocument(); //打开一个xml xml.Load(path); //获取portConfigure配置节点 XmlNode portConfigure = xml.SelectSingleNode("Configure/portConfigure"); //读取节点数据

string xxx= portConfigure.SelectSingleNode("url").InnerText; //获取节点
 spa

相关文章
相关标签/搜索