获取Windows窗体应用程序执行目录的path
我想获得Windows窗体应用程序的执行目录的path。 (即,可执行文件所在的目录。)
有没有人知道在.NET中的内置方法来做到这一点?
Application.Current结果在一个appdomain http://msdn.microsoft.com/en-us/library/system.appdomain_members.aspx
这也应该给你的程序集的位置
AppDomain.CurrentDomain.BaseDirectory 
我似乎记得有多种方式获取应用程序的位置。 但是这个在过去至less为我工作过(我已经做了winform编程已经有一段时间了:/)
在VB.NET中
 Dim directory as String = My.Application.Info.DirectoryPath 
在C#
 string directory = AppDomain.CurrentDomain.BaseDirectory; 
这可能有帮助;
 Path.GetDirectoryName(Application.ExecutablePath); 
这里也是参考
  System.Windows.Forms.Application.StartupPath将解决你的问题,我想 
这两个例子都在VB.NET中。
debuggingpath:
 TextBox1.Text = My.Application.Info.DirectoryPath 
EXEpath:
 TextBox2.Text = IO.Path.GetFullPath(Application.ExecutablePath) 
看一下这个
 'as in import statement you have to mention the Imports System.IO & import System.Management 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 
 string apppath = (new System.IO.FileInfo (System.Reflection.Assembly.GetExecutingAssembly().CodeBase)).DirectoryName; 
Private Sub Main_Shown(sender As Object,e As EventArgs)处理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