2011-02-03 17 views
2

私のアプリケーションディレクトリを取得し、そのパスにファイル名を追加する必要があります。だから私はこのように使いました。アプリケーションフォルダを取得する必要があります

String kofaxTextFilePath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(File)).CodeBase) + "\\KofaxBatchHistory.txt" 

したがって、このようなパスが得られます。

“file:\\C:\\Documents and Settings\\MyApplication\\ KofaxBatchHistory.txt” 

しかし、私は、この文字列に任意のものをやって持つ唯一の

C:\\Documents and Settings\\MyApplication\\ KofaxBatchHistory.txt 

を取得する必要があり、それを直接取得する方法はありますか?

答えて

2
string myDir = System.Reflection.Assembly.GetExecutingAssembly().Location; 
myDir = System.IO.Path.GetDirectoryName(myDir); 
String kofaxTextFilePath = System.IO.Path.Combine(myDir, "KofaxBatchHistory.txt"); 
1

Assembly.Locationを試してください。

Assembly.GetAssembly(typeof(File)).Location 

または、(いっそ):

typeof(File).Assembly.Location 
関連する問題