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

相關文章
相關標籤/搜索