Search Amazon:

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

Sign In
  User Id 
  Password 


Submit Your Own Code and Articles




About TheScarms
About TheScarms

Ask me your programming questions

I read every email and answer all I can.

User Feedback: Be the first to add a comment! Items to Show:     

     
You must log in to post feedback.
Comment:    
 

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

Email this page


TheScarms AppSentinel lets you securely copy protect and create evaluation versions of your software

TheScarms(tm) AppSentinel lets you quickly and easily create evaluation versions of your software and stop unauthorized copying and unregistered use of your programs!

Get your free
trial copy today!


      The World's Number 1 Web Host

© Copyright 2008 TheScarms