kaisersoze
Centurion
- Joined
- Aug 27, 2003
- Messages
- 152
How do I append Lines to an existing file, if the file not found then create and append lines.
Dim nr As Integer = FreeFile() 'select a freefile
FileOpen(nr, "c:/file.txt", OpenMode.Append) 'open the file c:/file.txt as append
Print(nr, TextBox2.Text) 'write textbox2.text to the file
FileClose(nr) 'close the file if your done
Dim DoIwantToAppend As Boolean = True 'purely trivial boolean variable.
Dim SW As StreamWriter = New StreamWriter("C:\file.txt", DoIwantToAppend) 'second parameter is true, so we'll append.
SW.WriteLine(TB.Text) 'write to file.
SW.Close() 'close the stream so changes are made.