exeContext.ExePath

I'm having a hard time trying to discover my applications path in the form load event.

In VB6 it would look something like this:
myPath = application.exePath

After discovering that My.Application.CommandLineArgs.Item(0) doesn't always contain the applications path, I moved onto the new 2.0 exeContext class. Here's the code that doesNOTcompile:

Dim appInfoAs System.Configuration.ExeContext
Dim myPath As string

'**** Attempt #1
'***** Error: Type has no constructor
appInfo = New System.Configuration.ExeContext
myPath = appInfo.ExePath

'**** Attempt #2
'***** Error: No static methods
myPath = System.Configuration.ExeContext.ExePath

'**** Attempt #3 using the command line args instead of ExeContext
'***** Error: Index out of range
'myPath = System.IO.Path.GetFullPath(My.Application.CommandLineArgs.Item(0))

Please note that you'll have to add System.Configuration as a reference to the project.

Any working examples would be great! :)

Thanks

[1170 byte] By [JohnLieurance] at [2007-12-23]
# 1

Hi,

how about using one of the following?

Application.StartupPath

or

Application.ExecutablePath

Andrej

AndrejTozon at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

Thanks Andrej, that worked liked a charm and re-introduced me to the application object.

I learned about the applicaiton object (system.windows.forms.application) a while back but managed to get it confused with the my.application object. Now I know they are two totally different objects.

Thanks again,
Johnny

JohnLieurance at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...