so my project is a text editor and i am trying to make an open button and save. my code only opens the last part of the file it read. i was wondering if someone good help me or give any tips. thanks
Private Sub OpenToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
Dim fileString As String
Dim openStreamReader As StreamReader = New StreamReader("file.txt")
Dim reponseDialog As DialogResult
If openStreamReader IsNot Nothing Then
openStreamReader.Close()
End If
With OpenFileDialog1
.InitialDirectory = Directory.GetCurrentDirectory
.FileName = "file.txt"
.Title = "Select File or Directory for File"
reponseDialog = .ShowDialog()
If reponseDialog <> DialogResult.Cancel Then
openStreamReader = New StreamReader(OpenFileDialog1.FileName)
End If
End With
Do Until openStreamReader.Peek = -1
fileString = openStreamReader.ReadLine() & Environment.NewLine
RichTextBox.Text = fileString
Loop
End Sub