Hello guys and gals of the DaniWeb community, this time I need help in how to save text to a file in the text editing application I created. Well, I tried using the code below but it didn't do the work:

If (RichTextBox1.Text Is Nothing) Then
            MessageBox.Show("No text to save!")
            Return
        End If

        If (SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
            If (System.IO.File.Exists(SaveFileDialog1.FileName)) Then
                System.IO.File.Delete(SaveFileDialog1.FileName)
            End If
RichTextBox1.Text = (System.IO.File.WriteAllText(SaveFileDialog1.FileName))
        End If

And, I really need your help. I've tried almost everything I know. BTW, thanks in advance.

Edited 7 Years Ago by TechSupportGeek: n/a

Dim file As String = "c:\myfile.txt"
If System.IO.File.Exists(file) = True Then
Dim objReader As New System.IO.StreamReader(file)

TextBox1.Text = objReader.ReadToEnd
objReader.Close()
Dim file As String = "c:\myfile.txt"
If System.IO.File.Exists(file) = True Then
Dim objReader As New System.IO.StreamReader(file)

TextBox1.Text = objReader.ReadToEnd
objReader.Close()

Thanks but I don't want to save to a specific file. I want to use a SaveFileDialog that will allow the user to choose file name and save location. Anyone who actually knows?

This question has already been answered. Start a new discussion instead.