How to determine folder .exe was run from?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to find a way to determine what drive and folder path a
executable is run from (and them pass that as the defaul in a BrowseForFolder
dialog).

In VB6, there was a way to do this, reading the App.Path property. What is
the equivalent in Visual Basic .NET?
 
Use:

System.AppDomain.CurrentDomain.BaseDirectory()

if you want you can make a function to do this:

\\
Public Function AppPath() as String
Return System.AppDomain.CurrentDomain.BaseDirectory()
End Function
//

Hope this helps,
Norst
 
Hi Jethro

They made it more pricise what it is.

application.startuppath

I hope this helps,

Cor
 
hmmmmm

i use this
System.Environment.CurrentDirectory

as i found that application.startuppath fails on dll`s
 
M. Posseth said:
i use this
System.Environment.CurrentDirectory

Note that the current directory can be changed while the application is
running, for example, when using a 'FileDialog'.
 
Jethro Bodine said:
I am trying to find a way to determine what drive and folder path a
executable is run from (and them pass that as the defaul in a
BrowseForFolder
dialog).

In Windows Forms applications you can use 'Application.StartupPath'. For
class libraries and other types of applications, you may want to use the
code below:

\\\
Imports System.IO
Imports System.Reflection
..
..
..
Private Function ApplicationPath() As String
Return _
Path.GetDirectoryName([Assembly].GetEntryAssembly().Location)
End Function
///
 
Thanks Herfried

Indeed i should better use a alternative method

however in my situation this will not happen so soon ,,,, just looked in
the code where i currently use it
they are web projects , and Dll`s ( but it is a potential big )

in my executables i use application.startuppath

however i found that this will not work in a Dll

i wonder if this will work in both executables as dll`s

System.AppDomain.CurrentDomain.BaseDirectory()

cause it sounds to me as a better generic alternative ( if this works
ofcourse in both )
 
But Herfried, that will only give you the current assembly & not a different
one executing as a different process. So, you cannot really use it.

Crouchie1998
BA (HONS) MCP MCSE
 
Crouchie1998 said:
But Herfried, that will only give you the current assembly & not a
different
one executing as a different process. So, you cannot really use it.

I understand what you mean, but the OP clearly stated that he is looking for
an equivalent of VB6's 'App.Path'.
 
Back
Top