|DataDirectory| and Application startup

Hi

I'm working on an application that I use SQL 2005 Express mdf files to store data I use the default connection string that created by connection wizard to connect to the data file

I want to make sure that the mdf file is in it's location before using the tableadapter.update method to fill the data set at application startup

the only problem I had here is the |DataDirectory| that is in the connection string I want to know at run time to which folder it refere

my question here how I can programatically at runtime identify the |DataDirectory| is reffering to which folder so I can get the full path to the place of the data file

Thank you all

[687 byte] By [SamerSelo] at [2007-12-24]
# 1

During development the data directory points to the directory where the database lives relative to your application...once deployed you can get the deployment data directory using the applicationDeployment class....

Imports AD = System.Deployment.Application.ApplicationDeployment

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

adp = AD.CurrentDeployment

MessageBox.Show(adp.DataDirectory)

End Sub

DMan1 at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

the code is not working

it gives the error InvalidDeploymentException was Unhandled, Application identity is not set

and the code

MsgBox(My.Application.Deployment.DataDirectory)

also gives the same error.

SamerSelo at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3

DMan1 wrote:
...once deployed you can get that directory using the applicationDeployment class

Samer Selo wrote:
MsgBox(My.Application.Deployment.DataDirectory) also gives the same error.

"deployed "....deploymnet data directory...not your databases directory....To test the code, change the solution configuration from debug to release and rebuild the project....and then deploy (install) the code will give you the path to the deployment data directory....

to get the application startup and exe's path use and the users app data path...

MessageBox.Show(Application.StartupPath)

MessageBox.Show(Application.UserAppDataPath)

MessageBox.Show(Application.ExecutablePath)

Sorry about the confusion

DMan1 at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4
thank you
SamerSelo at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...