I would like to get the path to the execution directory of a Windows Forms application. (That is, the directory in which the executable is located.)
Does anyone know
string apppath =
(new System.IO.FileInfo
(System.Reflection.Assembly.GetExecutingAssembly().CodeBase)).DirectoryName;
In VB.NET
Dim directory as String = My.Application.Info.DirectoryPath
In C#
string directory = AppDomain.CurrentDomain.BaseDirectory;
Private Sub Main_Shown(sender As Object, e As EventArgs) Handles Me.Shown
Dim args() As String = Environment.GetCommandLineArgs()
If args.Length > 0 Then
TextBox1.Text = Path.GetFullPath(Application.ExecutablePath)
Process.Start(TextBox1.Text)
End If
End Sub
System.Windows.Forms.Application.StartupPath
will solve your problem, I think
This could help;
Path.GetDirectoryName(Application.ExecutablePath);
also here is the reference
Check this out:
Imports System.IO
Imports System.Management
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = Path.GetFullPath(Application.ExecutablePath)
Process.Start(TextBox1.Text)
End Sub
End Class