Sunday, June 26, 2016

Read and Save .TXT file - VB.Net


READ .TXT File
'TextBox7.Text - browsed file to load
'TextBox8.Text - display
'------------------------------------------
         Try
            Dim objreader As New System.IO.StreamReader(TextBox7.Text)
            TextBox8.Text = objreader.ReadToEnd
            objreader.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
'------------------------------------------


SAVE .TXT File
'TextBox7.Text - browsed file to save as 
'TextBox8.Text - display
'------------------------------------------
        Try
            Dim objwrite As New System.IO.StreamWriter(TextBox7.Text)
            objwrite.Write(TextBox8.Text)
            objwrite.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
'------------------------------------------

No comments: