How to: Read Text from Files with a StreamReader (Visual Basic)
The My.Computer.FileSystem object provides methods to open aand a . These methods, OpenTextFileWriter and OpenTextFileReader, are advanced methods that do not appear in IntelliSense unless you select the All tab.
To read a line from a file with a text reader
Use the OpenTextFileReader method to open the TextReader, specifying the file. This example opens the file named testfile.txt, reads a line from it, and displays the line in a message box.
The file that is read must be a text file.
Do not make decisions about the contents of the file based on the name of the file. For example, the file Form1.vb may not be a Visual Basic source file.
Verify all inputs before using the data in your application. The contents of the file may not be what is expected, and methods to read from the file may fail.
To read from a file, your assembly requires a privilege level granted by the Access Control Lists (ACLs).class. If you are running in a partial-trust context, the code might throw an exception due to insufficient privileges. For more information, see . The user also needs access to the file. For more information, see