How to: Append to Text Files in Visual Basic
The WriteAllText method can be used to append to a text file by specifying that the
append parameter is set to
To append to a text file
WriteAllTextmethod, specifying the target file and string to be appended and setting the
This example writes the string
"This is a test string."to the file named
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
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).