2013-11-03 80 views
0

我試圖執行一個工具-EXE位於與主EXE相同的目錄中。 對於這個我想首先得到使用Assembly.GetExecutingAssembly過程中的exe文件名,然後讓使用IO.Path.GetDirectoryNameSystem.IO.Path.GetDirectoryName使路徑無效

//1 
String exePath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase; 
//2 
String ncpath = System.IO.Path.GetDirectoryName(exePath); 

1返回「文件的目錄:/// C:/開發/ RC_trunk/bin/Release/ResultConfirmation.EXE「 它是一個URI。不完全是我需要的,但確定。

2返回「file:\ C:\ Development \ RC_trunk \ bin \ Release」這似乎是一個簡單的[/] + \替換。

我使用錯誤的API來解決我的問題嗎?

P.S. IDE是VS2008

回答

1

要獲取應用程序目錄,請嘗試AppDomain.CurrentDomain.BaseDirectory

查看Best way to get application folder path的其他訪問目錄的方法。

+0

好吧,看起來有一些可能性爲新手選擇一個錯誤的。感謝您的鏈接! –

1

使用此而不是爲第1步)

string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;