making APP.Path

shingo99

Active member
Joined
Jul 19, 2004
Messages
31
hi
can i know how to make app.path that is normally use in VB6
into VB.Net coding?
Code:
Data Source=C:\Documents and Setting\VB.Net\bin\cinema.mdb
this code is currently how i connect to my database
but when i move my program to other computer i will have to reset it again
so can teach me how to make it to app.path or something similiar
thank you in advance
 
PlausiblyDamp said:
Application.ExecutablePath is probably the one you are after.
how do i do this Application.ExecutablePath?
im sort of new to this VB.Net coding
i tried..but error keep coming
Code:
Data Source=Application.ExecutablePath\VB.Net\bin\cinema.mdb
am i doing this correctly?
 
shingo99 said:
how do i do this Application.ExecutablePath?
im sort of new to this VB.Net coding
i tried..but error keep coming
Code:
Data Source=Application.ExecutablePath\VB.Net\bin\cinema.mdb
am i doing this correctly?

[CS]
DataSource = Application.ExecutablePath + "\\cinema.mdb";
[/CS]
[VB]
DataSource = Application.ExecutablePath + "\\cinema.mdb"
[/VB]


VB.net and C# just incase. You have a space in your variable name and you must tell it to append the new text on the end of Application.ExecutablePath.

I dont know why you are adding \bin and such to it, as the executable file should already be in the bin directory.
 
Last edited by a moderator:
for vb.net your going to want to use :
DataSource = Application.StartupPath + "\cinema.mdb"

instead of:
DataSource = Application.ExecutablePath + "\cinema.mdb"
 
As VbStudent302 suggested Application.StartupPath is the way to go. By using Application.ExecutablePath you are returning the path complete with application name, which would essentially be telling it to do something like this....

C:\Documents and Setting\VB.Net\bin\application.exe\cinema.mdb

instead of

C:\Documents and Setting\VB.Net\bin\cinema.mdb

On a side note Im sure when I tried to use StartupPath when launching an application from a shortcut rather than direct from the exe I encountered some problems. It was probably almost a year ago now and after a quick test I cant emulate it, but Im sure it used to return the path to the shortcut rather than the exe, was this changed in a newer version of the framework or did I just imagine it.
 
Back
Top