VB6には、実行ファイルのあるフォルダのパスを取得する、App.Path()
という関数があります。
今回は、C#/VB.NET で同じことを行なう方法を紹介します。
実行ファイルのパスを取得する
実行ファイルのパスを取得するには、次のようにします。
Dim apppath =
System.Reflection.Assembly.GetExecutingAssembly().Location
string appPath =
System.Reflection.Assembly.GetExecutingAssembly().Location;
これで、exeファイルのパスを取得できます。
VB6 の App.Path と同じことを行なうには
VB6には、実行ファイルのあるフォルダのパスを取得する、App.Path()
という関数があります。
C#/VB.NET で同じことを行なうには、以下のようにします。
Public Function GetAppPath() As String
Return System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().Location)
End Function
public static string GetAppPath()
{
return System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().Location);
}
まとめ
実行ファイルのフォルダパスは、何かと必要になります。
プロジェクトで一つ定義しておくと、便利ですね。