2012-10-09 71 views
0

我有一個DLL需要打開一個Excel文件,但我似乎無法創建文件的路徑。 excel文件是一個必須用來與用戶將瀏覽並打開的excel文件進​​行比較的模板。在DLL中找到excel文件的路徑

使用一個exe文件爲我的應用程序時,我以前用這個代碼:

string path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "Data\\BulkMaintenanceExample.xls"); 

但一個DLL它似乎並沒有工作。有任何想法嗎?

回答

1

嘗試以下,以獲得裝配路徑:

var dir = AppDomain.CurrentDomain.BaseDirectory; 

//get the full location of the assembly with DaoTests in it 
string fullPath = System.Reflection.Assembly.GetAssembly(typeof(DaoTests)).Location; 
string theDirectory = Path.GetDirectoryName(fullPath); 

string filePath = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath; 
return Path.GetDirectoryName(filePath); 
+0

說實話,我已經忘記了,包括文件夾和Excel文件調用程序可執行程序。管理解決這個問題。感謝您的幫助,雖然我測試了你的方式,它的工作很好。 –