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

  • Thread starter Thread starter Bill Nguyen
  • Start date Start date
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 \
 
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
 
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]
 
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.
 
Perfect!
Thanks Mr. B, CMG, and Rob for your quick response!
Bill
 
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]
 
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
 
* "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
///
 
Hi Herfried,

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

appPath = System.Windows.Forms.Application.StartupPath

Cor
 
* "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.
 
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
 
* "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.
 
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

Back
Top