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