How can i copy a directory path in a string?

For example, the Location of the file is "C:\Folder1\Folder2\mydatabase.mdb".

i have an existing code,

Dim dbpath as String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim OpenFileDialog As New OpenFileDialog
    OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
    OpenFileDialog.Filter = "Access DB 2007 (*.accdb)|*.accdb|Access DB 2003(*.mdb)|*.mdb"
    If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.Ok) Then
        Dim FileName As String = OpenFileDialog.FileName

        'dbpath = ??????????? location of the dbpath

    End If
End Sub

Please Help me, I need the path in order for me to Connect to another database dynamically..

Use Path class:
Dim dbpath As String = Path.GetDirectoryName(FileName)

HTH

Great! Its working, but does not include the "mydatabase.mdb".
The string only contains "C:\Folder1\Folder2"

how can i get the complete "C:\Folder1\Folder2\mydatabase.mdb"

I get it, thanks for the Idea. :)

i just change the
Dim dbpath As String = Path.GetDirectoryName(FileName)
to
Dim dbpath As String = Path.GetFullPath(FileName)

you are a great help! Thank you master :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.