changing directory to application path

  • Thread starter Thread starter dennist
  • Start date Start date
D

dennist

I am trying to change directories in my sub main to the
application path so that my connection string will be
short - i.e. the database is in the directory with the
vbproj and forms and NOT the binary directory with the
executable. Is this possible? Or should I put the
database with the executable?

In either case I imported system.io
I tried to make sense of

System.Reflection.Assembly.GetExecutingAssembly.Location
Note The Location property returns the full path
including the file name; the Path property returned only
the path.


and I tried chdir, path.getfullpath,

etc, but no luck so far.

Frankly, vb6 was far easier to use.

dennist
 
Well, there's good news and bad news. Here's my new code
from modPrimary:

Imports System.io

Module modPrimary
Friend gstrConn As String
= "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" 'H:\HasbaraNET\ado.net
tests\adonetTest\HasbaraSample.mdb;"




Public Sub Main()

Dim strPath As String
Dim strSubstring As String
Dim intIndexof As Integer
Dim cls1 As New Class1
strPath =
System.Reflection.Assembly.GetExecutingAssembly.Location
intIndexof = strPath.IndexOf("bin")
MsgBox(intIndexof.ToString)
strSubstring = strPath.Substring(0, intIndexof)
MsgBox(strSubstring)
'MsgBox(strPath)
'strPath = System.IO.strPath.GetDirectoryName
("adonetTest")
ChDir(strSubstring)
gstrConn = gstrConn & "HasbaraSample.mdb;"
MsgBox(gstrConn)

'indexof
'substring
'MsgBox(strPath)
'strPath = cls1.GetDirectoryName("adonetTest")
'MsgBox(strPath)

Application.Run(New frmTest1)
End Sub


End Module

Now playing with the connect string the way I do along
with
System.Reflection.Assembly.GetExecutingAssembly.Location

I get the job done in an inelegant manner.

But using all sorts of tricks with
'strPath = System.IO.strPath.GetDirectoryName
("adonetTest")

I would just get blanks, empty nulls or nothings for the
directory name. No luck there.

My solution may not be elegant, but until an elegant
solution comes along, my kludge will work just fine.

Thansk for the information

dennis
 
Back
Top