Question how to set default application path

likejeewesh

Member
Joined
May 2, 2014
Messages
9
Programming Experience
5-10
suppose my database located in d:\access.mdb and i want do define this path as application automatically took the path of database when my application deployed on any pc directory
there is commnad in asp.net |datadirectory| that will pic database automatically where the application files are diployed. so any similar command for vb.net
 
The "|DataDirectory|" place-holder is resolved at run-time based on the type of application. If it's an ASP.NET application then it resolves to the App_Data folder. If it's a Windows application deployed using ClickOnce then it resolves to a special data folder managed by ClickOnce. If it's a Windows application not deployed using ClickOnce then it resolves to the same folder that the current EXE was run from. You can also change the data directory path at run-time via the current AppDomain.
 
|datadirectory| in windows application not working plz do one example at your system then reply the result

It works. It does what it's supposed to do. If you don't get the expected result then you're expecting it to do something that it's not supposed to do. "|DataDirectory|" works fine. It's your application that doesn't so that's what you need to fix. If you expect us to help you fix it then provide us with the relevant information to do so.
 
when i place |datadirectory| it will give error "Could not find file 'F:\Practical_duty\PracticalDuty\PracticalDuty\bin\Debug\PracticalDuty.accdb'."
 
i want to get folder path which consist my database

How about you answer my question? If you expect to use "|DataDirectory|" and have it find your data file then you have to put your data file in the right place. It's not going to magically find it somewhere else. The error message has told you where it expects to find the file. Have you put it there or not? If you haven't then of course it doesn't work: you did it wrong.
 
Hi, I agree with the other reply's. Please formulate your question more precisely.
If it's the application start-up folder you are after then in VB.net you can use dim strPath as String = Application.StartupPath().
This will give you the path to the folder where the application .exe file is.
If your data folder is inside the same folder as the .exe file then all you need to do is tag the folder and filename onto the path. (strpath & "\yourDatafolder\PracticalDuty.accdb"
Of course you can always use the App.config file. That way you can point to the path anywhere on your network. That way you don't have to move the database at all.
 
Hi, I agree with the other reply's. Please formulate your question more precisely.
f it's the application start-up folder you are after then in VB.net you can use dim strPath as String = Application.StartupPath().
This will give you the path to the folder where the application .exe file is.
If your data folder is inside the same folder as the .exe file then all you need to do is tag the folder and filename onto the path. (strpath & "\yourDatafolder\PracticalDuty.accdb"

You don't even have to do that. For a Windows application not deployed using ClickOnce, "|DataDirectory|" will resolve to the same folder path as Application.StartupPath so there's no need for any string concatenation. You just use "|DataDirectory|" in the literal string. That means that you can put your connection string in the config file and it will dynamically resolve the path at run time without any code, so there's no need to do anything between testing and release as the connection string will just work. That's assuming that you've put the file in the right place to begin with.
 
Back
Top