Writing files,paths etc

  • Thread starter Thread starter HardySpicer
  • Start date Start date
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
 
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.)
 
Back
Top