simple way to create and save a text file

do not make name changes

 

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim TargetFile As StreamWriter

 

        Try

            TargetFile = New StreamWriter("C:\newfile.txt", True)

        Catch

            MsgBox("Error opening " & "C:\newfile.txt")

        End Try

 

        Try

            TargetFile.WriteLine(Now())

            TargetFile.WriteLine("my new file")

        Catch

            MsgBox("Error writing file")

        End Try

 

        TargetFile.Close()

        MsgBox("Text saved to " & ("C:\newfile.txt"))

    End Sub