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.BaseDirectory

string path = AppDomain.CurrentDomain.BaseDirectory+"XXX.xml";
XmlDocument xml = new XmlDocument();
//打开一个xml

xml.Load(path);
//获取portConfigure配置节点
XmlNode portConfigure = xml.SelectSingleNode("Configure/portConfigure");
//读取节点数据

猜你喜欢

转载自www.cnblogs.com/Xanthus/p/11137498.html
今日推荐