How do I get my .NET application's path in VB or C#?

In Visual Basic 6 you could use App.Path to see where your application's executable resides.

In VB.NET you need to use the Application object and its ExecutablePath property to get the path for the executable file that started the application, including the executable name:

    Dim aPath As String = Application.ExecutablePath()

To get the path for the executable file that started the application, without the executable name use:

    Dim aPath As String = Application.StartupPath()

The C# code would be:

    string aPath1 = Application.ExecutablePath;
    string aPath2 = Application.StartupPath;

You can also use the System.Reflection namespace to get the properties of your Assembly. Try this VB.NET code:

    Dim aPath As String 
    Dim aName As String 

    aName = _
      System.Reflection.Assembly.GetExecutingAssembly. _
      GetModules()(0).FullyQualifiedName    

    aPath = System.IO.Path.GetDirectoryName(aName) 

    '
    ' Or
    '
    aPath = System.Reflection.Assembly. _
            GetExecutingAssembly.Location




About TheScarms
About TheScarms


Sample code
version info

If you use this code, please mention "www.TheScarms.com"

Email this page


© Copyright 2024 TheScarms
Goto top of page