AppPath() replacement

  • Thread starter Thread starter Guest
  • Start date Start date
* "=?Utf-8?B?QW5hbGlhIEJlbHRyYW4=?= said:
How do I get the path where application is running?

\\\
Imports System.IO
Imports System.Reflection
..
..
..
Private Function ApplicationPath() As String
Return _
Path.GetDirectoryName([Assembly].GetExecutingAssembly().Location)
End Function
///
 
Use System.Environment.CurrentDirectory:

'on a console app:
Module Module1

Sub Main()
Console.WriteLine(System.Environment.CurrentDirectory())
End Sub

End Module
 
* (e-mail address removed) (Alexandre Moura) scripsit:
Use System.Environment.CurrentDirectory:

'on a console app:
Module Module1

Sub Main()
Console.WriteLine(System.Environment.CurrentDirectory())
End Sub

This doesn't always return the application's startup path.
 
System.Environment.CurrentDirectory() simply returns the current directory
(which can change during execution or by starting the program with a
shortcut with a different "Start In" setting.

According to the Help (look under "App Object Changes"), the official
replacement for App.Path is:

System.Reflection.Assembly.GetExecutingAssembly.Location

Beware, because this returns the filename of the Exe or dll as well - you'll
need to strip this off to get the directory. Also if the code is in a dll
that is in a different directory than your current application, it will
return that path instead.

If you want to get the path of the main executable that started the
application, use

System.Reflection.Assembly.GetEntryAssembly.Location

Instead

Hope this helps,

Trev.
 
Yep, you guys are right.

--------------------
From: (e-mail address removed) (Herfried K. Wagner [MVP])
Newsgroups: microsoft.public.dotnet.languages.vb
Subject: Re: AppPath() replacement
Date: 05 Dec 2003 00:22:18 +0100
Lines: 15
Sender: Administrator@FAMILIE-IF1R60H
Message-ID: <[email protected]>
References: <[email protected]>
NNTP-Posting-Host: v208-105.vps.tuwien.ac.at (128.131.208.105)
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: news.uni-berlin.de 1070580438 72323595 128.131.208.105 ([208219])
X-Face: vJn^g[Lkg9YfJ,Oj#{Y[')WBo<1kS#Rc3Vb!D;jf$;OZ%<"'z+DX"K/m)h\Gi;e-AYsc%'CmL~Ix
@YEq$}A>^]KbF1.Z|=/'*CcB[f+8(m&vP.u4+P.q$n]?[s>nnFu/8EuC?h[c\#wR{ok_um~57to=
P=1"{qO1e%A2~nS?<[o`jn?C/-}7Mbz~L)WI=5VL!*xU#^d
User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Common Lisp (Windows)) Hamster/2.0.0.1
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA06.phx.gbl!TK2MSFTNGXA0
5.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!newsfeed01.sul.t-o
nline.de!t-online.de!fu-berlin.de!uni-berlin.de!v208-105.vps.tuwien.ac.AT!no
t-for-mail
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.languages.vb:161503
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

* (e-mail address removed) (Alexandre Moura) scripsit:
Use System.Environment.CurrentDirectory:

'on a console app:
Module Module1

Sub Main()
Console.WriteLine(System.Environment.CurrentDirectory())
End Sub

This doesn't always return the application's startup path.
 
Back
Top