Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Application Path 1

Status
Not open for further replies.

khowell78737

Programmer
Nov 18, 2003
22
US
In asp.net, you can set up a DSNless connection by using the server.mappath method...

ie.

DSN= DSN & Server.MapPath("data\rio.mdb")

In vb.net, I can't seem to find a simple way to get the root path of the application.

I've tried application.startupPath, but I get the "/bin" directory, not its parent directory.

I've also tried the other various application methods that relate to paths.. but they give me everything but...

I'm sure that this is a simple problem with me just overlooking the obvious in some namespace... but...

Thanks for your help!
Kevin Howell
 
You are right to use Application.StartupPath but this is the folder containing the .exe file.

When running under VS.NET by default this will be the bin folder of whatever configuration you are building.

In a live installation it will probably return the value you want as the .exe will now be in the 'right' folder.

One solution is to use compile time constants with #If statements to modify the code so that you insert \..\.. before the \bin part of Application.Startup during development. This will get you back up to the folder you wanted.

Alternatively you could include it as a key your config file but this is can be difficult manage when deploying it.

Finally you can use Application.UserAppDataPath or Application.LocalUserAppDataPath but you'll have to use this everywhere in the app that refers to this folder.
 
Thank you for your reply.

I am have gotten around the problem, albiet inelegantly, buy using "left" and "len" to strip the "/bin"

As I understand what you are saying, when a user installes this on his system, this solution will break.

Please explain what a "compile time constant" is and how to implement it.

Also, when I used UserAppDataPath and LocalUserAppDataPath, I got the "My Documents" folder. How can I set "UserAppDataPath" to something like "/data/database.mdb?

Finally...
In vb 5 & 6 there was "app.path" which worked in development. Am I missing the value of making it more granular but more difficult to manage? OR, am I just missing the point altogether?? <g>

Thanks!
Kevin Howell
 
Try:

Dim strPath as String= System.Reflection.Assembly. _
GetExecutingAssembly().Location

Little bit longer then App.Path but its only way if you want to retrieve path of Class Library for ex.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top