Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

for my connection string, I use this:

<connectionstring="provider=microsoft.data.jet.oledb.4.0;data source=|datadirectory|\db.mdb;...... >

I want to know what is the datadirectory while running the application in debug.
how can I do that?

by the way- my connectionstring is in the app.config of a different project ("DAL" project) from my application forms ("app" project)

thanx!
Posted

1 solution

My memory is a bit fuzzy but I believe you can get the value of DataDirectory with:
Dim path As String = CStr(AppDomain.CurrentComain.GetData("DataDirectory"))

I haven't tried it and only vaguely remember seeing it somewhere.
 
Share this answer
 
Comments
danait25 1-Mar-12 1:03am    
well, I tried it and it returns empty string..
any other suggestions?...
Dave Kreskowiak 1-Mar-12 10:06am    
In that case, it's not set. You have to use a couple of rules to determine what the default path is.

If the application is installed on the users local machine, then the DataDirectroy will be the folder where the .EXE was launched from, usually under Program Files\SomeFolder. Use Application.StartupPath to get that.

If the application is deployed using ClickOnce, I think you can get the path from ApplicationDeployment.DataDirectory. Though, I never ClickOnce, so I'm not about to claim being an expert in it.
danait25 5-Mar-12 0:26am    
thanks - It worked

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900