我需要一些帮助来找到在动态链接库的VB.Net中的App.Path和App.EXEName的等价物。
谢谢你的帮助。
发布于 2012-02-07 00:21:02
根据MSDN (App Object Changes in Visual Basic .NET )的说法,两者的替代方案是
System.Reflection.Assembly.GetExecutingAssembly().Location
它包含完整路径(App.Path
)和文件名(App.EXEName
)。您可以使用Path
类中的帮助器方法拆分信息:
' Import System.Reflection and System.IO at the top of your class file
Dim location = Assembly.GetExecutingAssembly().Location
Dim appPath = Path.GetDirectoryName(location) ' C:\Some\Directory
Dim appName = Path.GetFileName(location) ' MyLibrary.DLL
UPDATE (感谢评论者):如果您在DLL中执行这段代码,并且想要调用DLL的的名称,则需要使用GetEntryAssembly
而不是GetExecutingAssembly
。请注意,如果从非托管EXE调用DLL,则GetEntryAssembly
可能返回Nothing
。
发布于 2021-01-23 05:11:53
你可以拿到它,
Application.ExecutablePath
它包含目录和可执行文件,要将其分开,可以使用System.IO.Path
类
Dim ExePath = Application.ExecutablePath
Dim ExeFolder = Path.GetDirectoryName(ExePath) ' which is App.Path in VB6
就这样。
发布于 2021-07-24 19:37:26
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim path As String = System.IO.Path.GetFullPath(Application.StartupPath & "\test.txt")
Dim lines = File.ReadAllLines(path)
Dim firstLine = lines(0)
Dim fields = firstLine.Split(Microsoft.VisualBasic.ChrW(44))
' TextBox1.Text = ExeFolder
'Id = fields(4)
TextBox2.Text = fields(0)
End Sub
https://stackoverflow.com/questions/9163196
复制相似问题