File path in Visual Basic .NET

Find this useful? Support us: Star on GitHub 6
Category: File | Language: Visual Basic .NET

In order to get the file path in Visual Basic .NET, you can use the following method:

Dim filePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)

Here is an example of how you could use it:

Sub GetFilePath()
    Dim filePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
    MsgBox("The file path is: " & filePath)
End Sub

When you run this code, you will get a message box that displays the file path of your application. This can be especially useful if you need to access files that are located in the same directory as your application.