[VB.NET] lecture fichier texte

bonjour ,

j'ai ajouté un bouton " open" pour mon application sur vb.net , pour ouvrir un fichier texte . j'ai fait le code , mais quand j'ai cliqué sur le bouton , une fenetre de dialogue m'a apparait sans ouvrir le fichier , voila le code :

  Private Sub Button_open_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_open.Click
        Dim open As New OpenFileDialog()
        open.InitialDirectory = "C:\"
        open.Title = "Open a Text File"
        open.ShowDialog()
        Try
            Dim sr As StreamReader = New StreamReader("TestFile.txt")
            Dim line As String
            line = sr.ReadLine(ComboBox_D_in.Text) : line = sr.ReadLine(ComboBox_D_mm.Text) : line = sr.ReadLine(ComboBox_D_unit.Text)
            line = sr.ReadLine(TextBox_H.Text) : line = sr.ReadLine(ComboBox_H.Text)
            line = sr.ReadLine(TextBox_factor_E.Text)
            line = sr.ReadLine(TextBox_factor_F.Text)
            line = sr.ReadLine(TextBox_factor_T.Text)
            line = sr.ReadLine(TextBox_t.Text) : line = sr.ReadLine(ComboBox_t.Text)
            line = sr.ReadLine(TextBox_W.Text) : line = sr.ReadLine(ComboBox_W.Text)
            line = sr.ReadLine(TextBox_P.Text) : line = sr.ReadLine(ComboBox_P.Text)
            line = sr.ReadLine(TextBox_SMYS.Text) : line = sr.ReadLine(ComboBox_SMYS.Text)
            line = sr.ReadLine(TextBox_F.Text) : line = sr.ReadLine(ComboBox_F.Text)
            line = sr.ReadLine(TextBox_WG.Text) : line = sr.ReadLine(ComboBox_WG.Text)
            While (line <> Nothing)
                Console.WriteLine(line)
                line = sr.ReadLine(ComboBox_H.Text)
            End While
            sr.Close()
        Catch ex As Exception
            Console.WriteLine("The file could not be read:")
            Console.WriteLine(ex.Message)
        End Try
end sub
bandicam 2015 03 09 18 34 47 322
Rechercher des sujets similaires à "net lecture fichier texte"