How to: Append to Text Files in Visual Basic
The My.Computer.FileSystem.WriteAllText Method can be used to append to a text file by specifying that the append parameter is set to True.
To append to a text file
Use the WriteAllText method, specifying the target file and string to be appended and setting the append parameter to True.
This example writes the string "This is a test string." to the file named Testfile.txt.
Dim inputString As String = "This is a test string." My.Computer.FileSystem.WriteAllText _ ("C://testfile.txt", inputString, True)
The following conditions may cause an exception:
The path is not valid for one of the following reasons: it is a zero-length string, it contains only white space, it contains invalid characters, or it is a device path (starts with \\.\) (ArgumentException).
The path is not valid because it is Nothing (ArgumentNullException).
The file is in use by another process, or an I/O error occurs (IOException).
The path exceeds the system-defined maximum length (PathTooLongException).
A file or directory name in the path contains a colon (:) or is in an invalid format (NotSupportedException).
The user lacks necessary permissions to view the path (SecurityException).