filenotfoundexception error- c#- with database

hello,
i have a C# windows form application w/microsoft access database.in the visual studio 2008 enviroment- it runs with no problems. I can also go to debug folder and copy the exe file and database- and it works ( although- this is not correct way to deploy a c# app).
 database is on local network-  txt file in debug folder - the program.cs file loads form1 and checks for the txt file. (i read that txt file has to be in same folder where application .exe resides).
Then it checks for database and loads application.

Code in the program.sc file:
System.IO.StreamReader file = new System.IO.StreamReader(Application.StartupPath + "\\dbpath.txt");
Code in form1:
OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Program.dbPath + "\\data13.mdb");  
Problem:
am getting a filenotfoundException when try to deploy it.
In the app.publish folder- there is setup.exe, publish htm, project ### application, and applicatoin files folder - if that is what is supposed to be created there?
It says " could not find "C:\Documents and settings\name\local settings\apps\2.0\ etc....
\dbpath.txt"

Why is it looking there for the txt file?
thank you
     
davetoughAsked:
Who is Participating?
 
Jacques Bourgeois (James Burger)Connect With a Mentor PresidentCommented:
The file must first be part of your project. If it is not, you can add it by right-clicking on the project in the Solution Explorer, and point to the file through the Add...Existing Item menu entry.

Once the file is in the Project, click on it in the Solution Explorer, and set its Build Action to Content in the Properties window. A file flagged as Content is usually added in the list of Application Files distributed through ClickOnce, and installs in the same directory as the application.
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
It is looking there because when you install a program with ClickOnce (this is what you seem to be using for deployment), by clicking the Setup.exe or activating the install from publish.htm, the application is installed in "C:\Documents and settings\name\local settings\apps\2.0\". So Application.StartupPath leads you there.

You probably did not include the dbpath.txt file in your deployment, so the FileNotFoundException.
0
 
davetoughAuthor Commented:
do i need to use a different deployment method - to include the dbPath.txt file ?
I do not see how to add i with click once
thank you
0
 
davetoughAuthor Commented:
thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.