如何获取dll文件所在路径?

来源:互联网 发布:淘宝外卖 编辑:程序博客网 时间:2024/05/02 12:44

应用场景,主程序有一个文件夹,下面有子程序。
主程序中点击按钮,打开子程序。
与子程序平级的dll文件中有句话需要以dll路径为基础调用x文件实现某些功能。

问题:
如果打开子程序文件夹,双击打开子程序,一切正常
如果从主程序中使用

string pathFileName = AppDomain.CurrentDomain.BaseDirectory + @"\地闪数据时空特征分析\地闪数据时空特征分析.exe";            if (File.Exists(pathFileName))                Process.Start(pathFileName);            else                throw new FileNotFoundException("您所查找的文件不存在,请重新安装本软件");


子程序会报错,错误原因:调用x文件失败,因为路径错误;路径起点被移动到主程序了,自然要报错,

原先的查找代码:

string curDllRelativePath = Environment.CurrentDirectory;string curDllRelativePath = Directory.GetCurrentDirectory();


这两个都试了,不能解决问题。

 

 

解决方案:

AppDomain.CurrentDomain.BaseDirectory + @"\Surfer\level\leve" + maxValue.ToString() + ".lvl";


引以为戒。

原创粉丝点击