Avatar billede peanut2000 Nybegynder
01. december 2004 - 14:16 Der er 1 løsning

Openfildialog, mangler sti i textbox

Har følgende kode:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     
        OpenFile()



    End Sub

    Private Function OpenFile() As FileStream

        ' Displays an OpenFileDialog and shows the read/only files.

        Dim DlgOpenFile As New OpenFileDialog
        DlgOpenFile.ShowReadOnly = True
        Dim Fs As FileStream

        If DlgOpenFile.ShowDialog() = DialogResult.OK Then

            ' If ReadOnlyChecked is true, uses the OpenFile method to
            ' open the file with read/only access.

            If DlgOpenFile.ReadOnlyChecked = True Then

                Return DlgOpenFile.OpenFile()
                ' Otherwise, opens the file with read/write access.

            Else

                Dim Path As String = DlgOpenFile.FileName
                Return New FileStream(Path, System.IO.FileMode.Open, _
                        System.IO.FileAccess.ReadWrite)


            End If

        End If


    End Function

Har en textbox, hvordan får jeg den til at vise stien til den fil jeg vil åbne via openfiledialog
Avatar billede peanut2000 Nybegynder
01. december 2004 - 14:31 #1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        TextBox1.Text = OpenFile()

        'Dim myStream As Stream
        'Dim openFileDialog1 As New OpenFileDialog

        'openFileDialog1.InitialDirectory = "c:\"
        'openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
        'openFileDialog1.FilterIndex = 2
        'openFileDialog1.RestoreDirectory = True

        'If openFileDialog1.ShowDialog() = DialogResult.OK Then
        '    myStream = openFileDialog1.OpenFile()
        '    If Not (myStream Is Nothing) Then
        '        ' Insert code to read the stream here.
        '        myStream.Close()
        '    End If
        'End If



    End Sub

    Private Function OpenFile() As String

        ' Displays an OpenFileDialog and shows the read/only files.
        Dim path As String

        Dim DlgOpenFile As New OpenFileDialog
        DlgOpenFile.ShowReadOnly = True
        Dim Fs As FileStream

        If DlgOpenFile.ShowDialog() = DialogResult.OK Then

            ' If ReadOnlyChecked is true, uses the OpenFile method to
            ' open the file with read/only access.

            'If DlgOpenFile.ReadOnlyChecked = True Then

            '    Return DlgOpenFile.OpenFile()
            '    ' Otherwise, opens the file with read/write access.

            'Else

            path = DlgOpenFile.FileName
            'Return New FileStream(Path, System.IO.FileMode.Open, _
            '        System.IO.FileAccess.ReadWrite)




            'End If

        End If

        Return path


    End Function
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester