path to file

  • Thread starter Thread starter Laura K
  • Start date Start date
L

Laura K

I know how to connect to a database using a full path. Something like
C:\path to application\bin\database.mdb

How do I create a relative path so that my application is portable?

Thanks
Laura K
 
Hi Laura,

Assuming this is Access or something like that, than you can set the
connectionstring of the connection in the load event of your form. (Do not
delete the old one in the designer let everything there, only set it again
in the load event).

something as
conn.connectionstring = "xxxxxxx

I hope this helps?

Cor
 
didn't work.

It works with the full path but not with a relative path.

Any other suggestions?

Laura
 
Just use the database name rather than a full path or you should be able to
use stuff like

...\directory or .\directory.

You could get the best of both worlds and use the app.config. or an xml
file, or the registry to store the absolute values, and allow the program to
check to see if a key exists and if not simply set the connection string up
to the current directory
 
Use application.startuppath to get your working directory, store that in a
variable, and append that to your file names.
 
OK got it.

Apparently for a relative path one should omit the bin file as part of the
path.

I also tried the application.startuppath

Both ways worked find.

Thanks

Laura K
 
Back
Top