マイクロソフト系技術情報 Wiki」は、「Open棟梁Project」,「OSSコンソーシアム .NET開発基盤部会」によって運営されています。

目次

概要

調査したところ、

System.AppDomain.CurrentDomain.BaseDirectory

が推奨方法の既定値であるもよう。

方法

System

System名前空間のライブラリを使用するのが一般的。

System.AppDomain?

アプリケーションと同じディレクトリにあるファイルを検索する場合に使用する。

string path = System.AppDomain.CurrentDomain.BaseDirectory

System.Environment

環境変数の current directoryを取得する場合に使用する。

string path = System.Environment.CurrentDirectory

System.IO

System.Environmentと同じ、
環境変数の current directoryを取得する場合に使用する。

string path = System.IO.Directory.GetCurrentDirectory();

System.Reflection.Assembly

GetEntryAssembly?

EntryAssembly?メソッドでは、EXEなどのエントリポイントとなるアセンブリを取得する。

System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetEntryAssembly();
string path = myAssembly.Location;

GetExecutingAssembly?

ExecutingAssembly?メソッドでは、実行中のコードを含むEXEやDLLのアセンブリを取得する。

string path = System.Reflection.Assembly.GetExecutingAssembly().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開発


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS