Writing files,paths etc

H

HardySpicer

I read a file from

File.ReadAllLines(App_Path() & "\file_name.txt"))

Public Function App_Path() As String
Return System.AppDomain.CurrentDomain.BaseDirectory()
End Function

and it works fine when the file is in the bin directory and I run in
debug mode also when I build - it runs fine in the same directory..
However, if I build the project
it cannot find the file (the built program is at c:\program files
\myprog\myprog.exe lets say). How can I make a path such that no
matter where the user installs the program, the file path is valid. I
could put everything in say c:\myfiles I suppose but I want all data
files to be in the install directory.


Hardy
 
G

Göran Andersson

HardySpicer said:
I read a file from

File.ReadAllLines(App_Path() & "\file_name.txt"))

Public Function App_Path() As String
Return System.AppDomain.CurrentDomain.BaseDirectory()
End Function

and it works fine when the file is in the bin directory and I run in
debug mode also when I build - it runs fine in the same directory..
However, if I build the project
it cannot find the file (the built program is at c:\program files
\myprog\myprog.exe lets say). How can I make a path such that no
matter where the user installs the program, the file path is valid. I
could put everything in say c:\myfiles I suppose but I want all data
files to be in the install directory.


Hardy

Use Application.StartPath instead of the appdomain base directory.

(Use the Path.Combine method to add the file name to the path instead of
hard coding "\" in the string, then the code works for any file system.)
 

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