locked
Need Help in saving rich textbox text into batch file.

    Question

  • Hey I need help in saving the contents of a rich textbox into a batch file. The code that I written save it fines but when I open the batch file it seems to not recognize it as a batch file. Here is the code below:

    Try
                Dim savefiledialog1 As New SaveFileDialog
                savefiledialog1.Title = "Save As Batch File"
                savefiledialog1.FileName = ""
                savefiledialog1.Filter = "Visual Basic Script|*.bat"
                If savefiledialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                    RichTextBox1.SaveFile(savefiledialog1.FileName())
                End If

            Catch ex As Exception
                MsgBox("Error!", MsgBoxStyle.Critical)
            End Try

    Sunday, February 28, 2010 4:40 PM

Answers

  • If you place your cursor at the starting bracket for the method the system will indicate the bit that is missing - you need to indicate wheter or not the existing batch file will be overwritten.  Change the line to:

            My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName(), RichTextBox1.Text, False)

    Sunday, February 28, 2010 8:23 PM

All replies

  • The  SaveFile method a richtextbox saves the file in RTF format, which cannot be understood by the batch file processor.  Instead of

      RichTextBox1.SaveFile(savefiledialog1.FileName())

    use

     My.Computer.FileSystem.WriteAllText(savefiledialog1.filename(), RichTextBox1.Text)



     

    Sunday, February 28, 2010 8:01 PM
  • Sorry It did not work I keep getting an error, saying that overload resolution failed because WriteAllText does not support that many arguments.

    Sunday, February 28, 2010 8:15 PM
  • If you place your cursor at the starting bracket for the method the system will indicate the bit that is missing - you need to indicate wheter or not the existing batch file will be overwritten.  Change the line to:

            My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName(), RichTextBox1.Text, False)

    Sunday, February 28, 2010 8:23 PM
  • Hey thanks for your help I marked you as answer
    Sunday, February 28, 2010 10:34 PM