app path Help

kAnne

Active member
Joined
Jan 17, 2006
Messages
26
Programming Experience
1-3
Hi,

Im having some trouble specifying relative file paths in VB.NET (App path seems not to work outside VB6)

Ive tried pretty much all I can think of, but this leads me to the /bin directory of my folder which is not where the file I want is held!

Any suggestions?

Thanks :)
 
Hi,

Try this code it will check the file from the application directory.

't1.txt file is in the application directory
'to go to one parent directory use ..\
'in this case my application run from \AppFolder\bin\debug folder

If My.Computer.FileSystem.FileExists("..\..\t1.txt") = TrueThen
MsgBox("ok")
Else
MsgBox("no")
EndIf

Happy Coding...
 
Hi,

MY Namespace is only available in VS 2005 only. So if you are using .NET earlier use following code.

If System.IO.File.Exists("..\..\t1.txt") = True Then
MsgBox("ok")
Else
MsgBox("no")
End If

Happy Coding...
 
kAnne said:
Yeah, Ive tried that one...It takes me to /bin folder. Do I have to put the files I need in there?
When you debug the application runs default from \bin folder and this is what Application.StartupPath returns. When application is installed/distributed the path could be anywhere, but you'd still use Application.StartupPath. If you need access to an application file during debug you have to copy it to the debug folder.
 
Back
Top