「マイクロソフト系技術情報 Wiki」は、「Open棟梁Project」,「OSSコンソーシアム .NET開発基盤部会」によって運営されています。
調査したところ、
が推奨方法の既定値であるもよう。
System名前空間のライブラリを使用するのが一般的。
アプリケーションと同じディレクトリにあるファイルを検索する場合に使用する。
string path = System.AppDomain.CurrentDomain.BaseDirectory
環境変数の current directoryを取得する場合に使用する。
string path = System.Environment.CurrentDirectory
System.Environmentと同じ、
環境変数の current directoryを取得する場合に使用する。
string path = System.IO.Directory.GetCurrentDirectory();
EntryAssembly?メソッドでは、EXEなどのエントリポイントとなるアセンブリを取得する。
System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetEntryAssembly(); string path = myAssembly.Location;
ExecutingAssembly?メソッドでは、実行中のコードを含むEXEやDLLのアセンブリを取得する。
string path = System.Reflection.Assembly.GetExecutingAssembly().Location
Windows.Forms用
string path = Application.ExecutablePath;
string path = Application.StartupPath;
Tags: :.NET開発