Use streamwriter

dim oWrite as system.io.streamwriter
'openfile
oWrite = system.io.file.opentext("C:\sample")
'write textbox1.text to the textfile
oWrite.WriteLine(textbox1.text)
'leave a space
oWrite.WriteLine()
'close file
oWrite.close()

Hope that helps :)
Cheers,

Use streamwriter

dim oWrite as system.io.streamwriter
'openfile
oWrite = system.io.file.opentext("C:\sample")
'write textbox1.text to the textfile
oWrite.WriteLine(textbox1.text)
'leave a space
oWrite.WriteLine()
'close file
oWrite.close()

Hope that helps :)
Cheers,

This line gets an error:
oWrite = system.io.file.opentext("C:\sample")
This is the error:
Error 1 Value of type 'System.IO.StreamReader' cannot be converted to 'System.IO.StreamWriter'. C:\Documents and Settings\nevets04\Local Settings\Application Data\Temporary Projects\Employee Manager\Form1.vb 12 18 Employee Manager

Using sw As New System.IO.StreamWriter("C:\Sample.txt")    'Opens/creates file & StreamWriter object
    sw.WriteLine(TextBox1.Text)    'Outputs textbox value
End Using    'Closes & disposes StreamWriter object

Edited 7 Years Ago by TomW: n/a

Yeah, my bad mate.
if you want to write new lines in the existing text file, here is the code.

Dim oWriter As systems.io.Streamwriter
        oWriter = systems.io.File.AppendText("c:\sample.txt")
        oWriter.WriteLine("abc first")
        oWriter.WriteLine("haha")
        oWriter.WriteLine()
        oWriter.Close()
This article has been dead for over six months. Start a new discussion instead.