Including text files when publishing Visual Basic 2008 project

KayGee

Senior member
Sep 16, 2004
268
0
76
Hi, I am working on the source code for a VB 2008 project and have managed to get everything working like it should except for one tiny problem. It's an engineering application and uses data from four text files for part of the calculations. To read the data from the text files, I'm using the following line in my code :

FileOpen(iFileNum, "C:\AirProp\AirProp.txt", OpenMode.Input)

I'm using the same syntax for the other 3 files also. The four text files are crucial and the application can't run without them. When I build the application on my PC, it runs fine as long as the text files are in the directory specified above. But when I try to publish my application and create an "installation package" so that I can install and run it on any computer, I can't for the life of me figure out how to include the text files as part of the package, so that the installer automatically copies them into the correct directory on the target machine.

Can anybody please tell me what I'm doing wrong or point me to a link or other resource that has a solution to something like this? Thank you in advance.
 

WannaFly

Platinum Member
Jan 14, 2003
2,811
1
0
I haven't tried it in vs2008, but in vs2005 you right click your setup project and click view file system, then right click in the new pane, new special folder and put in its properties c:\aitprop, then in the pane to the right right click add file and point to yoru text files.

My menus might not be the same as above but the process should be real similar. BTW, Unless its a very small deployment its never a good idea to hard code a directory requirement.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
You can also include the text files in your assembly (or a satellite assembly) as resources, which might be a more robust solution over the long term. If you put them in a satellite assembly you can just replace that if the data changes in the future; meanwhile there aren't four user-editable text files on disk.
 

KLin

Lifer
Feb 29, 2000
30,427
745
126
Sounds like something that should be in a centralized database somewhere. Then you can change the data without deploying a new version of the app if any changes are required for calculations.
 

KayGee

Senior member
Sep 16, 2004
268
0
76
Thank you for the help guys. I really appreciate it. After doing some Googling, I made some changes. I changed the 4 lines where the text files are opened to the following :

FileOpen(iFileNum, My.Application.Info.DirectoryPath & "\..\AirProp\AirProp.txt", OpenMode.Input)

Following Markbnj's advice, I also added the folder "AirProp" and the four text files within it to the main project, so they show up in the Solution Explorer along with the other source code files. I can compile and build the application and it runs perfectly.

However, when I try running the application on another PC after installing the package that VB creates using "Click once" publishing, I get an unhandled exception because it installs the program into two folders under C:\Documents and Settings\student\Local Settings\Apps\2.0\6VY4DDZ4.O3E\A0W8CC3C.V8P. One of the folders contains the executable and the other contains the icon file and the AirProp folder (and its contents). The unhandled exception is :

System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Documents and Settings\student\Local Settings\Apps\2.0\6VY4DDZ4.O3E\A0W8CC3C.V8P\AirProp\AirProp.txt'.

I guess my question is how do I change the above line of code so that it installs everything in one folder. I tried using the following line, but then it throws up an error when building :

FileOpen(iFileNum, My.Application.Info.DirectoryPath & "\AirProp\AirProp.txt", OpenMode.Input)

The error is :

Could not find a part of the path 'C:\Documents and Settings\student\Desktop\XDimpleHx.NET\bin\AirProp\AirProp.txt'.

I'd really appreciate it if someone could point out what I'm doing wrong or just link me to a resource. Thanks again.