How to determine folder .exe was run from?

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?
 
P

Poohface

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
 
C

Cor Ligthert

Hi Jethro

They made it more pricise what it is.

application.startuppath

I hope this helps,

Cor
 
M

M. Posseth

hmmmmm

i use this
System.Environment.CurrentDirectory

as i found that application.startuppath fails on dll`s
 
H

Herfried K. Wagner [MVP]

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'.
 
H

Herfried K. Wagner [MVP]

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
///
 
M

M. Posseth

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 )
 
C

Crouchie1998

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
 
H

Herfried K. Wagner [MVP]

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'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top