dumb question - How can I get the app.path from .NET?

C

CMG

I usually put the following up with the declarations...
Dim AppFolder As String =
System.Windows.Forms.Application.ExecutablePath.Substring
(0,
System.Windows.Forms.Application.ExecutablePath.LastIndexO
f("\") + 1)

AppFolder then points to the exact folder ur exe is
running from with the trailing \
 
M

Mr. B

Bill Nguyen said:
what's the equivalent syntax for app.path in VB.NET?

Dim appPath As String ' Application Start Path

appPath = System.Windows.Forms.Application.StartupPath

And I think you need:

Imports System.IO


Regards,

Bruce
 
R

Rob Teixeira [MVP]

You were doing really well up to the ExecutablePath property :)
However, rather than manually parsing out the directory name, you might want
to consider using the System.IO.Path class instead.
There are occassions where your parsing can fail - for example, if the
application was run from a URL.

-Rob Teixeira [MVP]
 
C

CMG

Thanx for the info. Never ran a exe from an url befor,
prolly aint going to in the near future, so for now, this
is perfect for me. I was just trying to help the guy, i
am no where near an MVP or what so ever, i just started
vb.net a couple of months ago just for my own fun.
 
R

Rob Teixeira [MVP]

Oh, don't get me wrong, I'm not critisizing your response. Please continue
to contribute.
I was just adding info for everyone's benefit. We're all here to learn,
after all :)

-Rob Teixeira [MVP]
 
C

CMG

Hehe, sorry if my post seemed sarcastic, it was not ment
that way ;) i know you mean well, so do i, and in the
end, by trying to help some one i learned something
myself, so, i'm happy u responded also :)

Greetz,

CMG
 
H

Herfried K. Wagner [MVP]

* "Bill Nguyen said:
what's the equivalent syntax for app.path in VB.NET?

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

Cor

Hi Herfried,

Why not this one that Bill did give in this thread?

appPath = System.Windows.Forms.Application.StartupPath

Cor
 
H

Herfried K. Wagner [MVP]

* "Cor said:
Why not this one that Bill did give in this thread?

appPath = System.Windows.Forms.Application.StartupPath

We previously had a discussion in this group (I remember that Tom Spink
took part in this discussion). Somebody told us that this method may
return a wrong path on some Windows versions if the app is started by a
shortcut.
 
C

Cor

Herfried,

Thanks you for the explanation, maybe it is good to tell that next time in
your message.

(Not as a very bad bug please :))))

Cor
 
H

Herfried K. Wagner [MVP]

* "Cor said:
Thanks you for the explanation, maybe it is good to tell that next time in
your message.

(Not as a very bad bug please :))))

I am not even sure if this really occurs on some systems.
 
B

Bill Nguyen

CMG;
Can you help me further by telling me where "NP" came from? :)
As a matter of fact, I'm looking for some help in .NET for my upcoming
projects. Do you want to lend me a hand?
Thanks
Bill aka "NP" :)
 

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