I have a application that run in a directory like D:\App,
but i put the data directory to D:\App\Data.
I want to konw in my Application how to Access it
I have a application that run in a directory like D:\App,
but i put the data directory to D:\App\Data.
I want to konw in my Application how to Access it
How to access the data of Access that in the difference directory?
Gemazz
I got the solution of second problem.
The frist problem i have to more details for your:
App folder
|-----Application.exe
|----Data folder.
+------ Data.mdb [sub folder of data.]
now i have to access the data.mdb in my Application.exe, however it is not hardcode like source="D:\Data\data.mdb";
notice:
the class to access data is not a form class, just a class like SQLHelper.so that it is can not using Application.StartupPath attribute!
understand
johnly Sam
So your main question is answered Excellent.
As for the second bit on the config file... every time you build your app (or any assembly for that matter), the app.config file that is part of your project is copied to the destination directory and renamed to the appropriate name, overwriting what ever might have been there before.
In order to avoid this happening, try editing the app.config file inside of your project (before building) rather than the AppName.exe.config file in your build directory.
Klaim
I guess I still don’t see the continued problem with the first question... you want to know how to find the datafile that is located in the directory ‘data’ which is located in the same directory as your application.
Using a line like what I provided above of:
Application.StartupPath + @"\Data\" + dataFileName
Where Application.StartupPath tells you the working path of the executable (usually the same dir as your app is in, and then appending on the directory within StartupPath the file is in. Finally you append the name of your data file which in my example was in the variable named dataFileName.
What remains the problem
awp001
If I understand you right... assuming your application is running in the directory specified by Application.StartupPath... that the data you want to open is in the Data directory that is contained within Application.StartupPath, you could determine the path to your desired file as simply as this:
FileStream file = File.Open(Application.StartupPath + @"\Data\" + dataFileName);
Is this what you are looking for
Ramesh Kumar.S
thanks for your response.
in fact the statement is right. but i want access the data in my ADO.NET
and the code contains in a normal class that no the Application variant.
my code like:
public static string ConnectionString
{
get{return Application.StartupPath + "/Data/sample.mdb";}
}
if the code contains in a class file that with namespace System.Form which is okay.
and other problem with me is:
i have created a file named App.exe.config and had lines:
<configruation>
<appSettings>
<add key="DAL" value="OledbDAL" />
</appSettings>
</configuration>
after i having run the app.exe that app.exe.config was deleted!
i can not understand it!