2012-11-02 106 views
2

我有一個名爲JIMS.Printing.dll的dll,放在主應用程序JIMS.exe的Reporting文件夾中。在.Net中獲取實際的dll路徑

但在調用模板文件夾內JIMS.Printing.dll代碼中報告裏面的一些文件,其運行JIMS.exe

時,我得到一個錯誤
JIMS.exe 
--------->Reporting 
------------------->JIMS.Printing.dll 
------------------->Templates 
-----------------------------> Files 

代碼:

string _templatePath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(JIMS.Printing.PrintInvoice)).Location), "Templates"); 

代碼來自JIMS.Printing.dll

JIMS.exe尋找JIMS.exe路徑\模板\文件裏面的文件, 但實際上這個文件在JIMS.Printing.dll路徑\模板\文件

+0

什麼是錯誤?你的問題是什麼? – prprcupofcoffee

回答

7

您可以使用:

Assembly.GetExecutingAssembly().Location 

,這將給你執行的程序集的路徑,然後使用:

System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) 

這將給包含文件夾。

+0

您可能還想看看這個答案:http://stackoverflow.com/a/283917/1306012 –

2

你可以試試這個: -

string path1= System.Reflection.Assembly.GetAssembly(typeof(DaoTests)).Location; 

string directory= Path.GetDirectoryName(path1); 
+0

這是我正在使用的,它不工作 –

相關問題