Export (0) Print
Expand All

FileSystem.OpenTextFileReader Method (String)

Opens a StreamReader object to read from a file.

Namespace:  Microsoft.VisualBasic.FileIO
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public static StreamReader OpenTextFileReader(
	string file


Type: System.String

File to be read.

Return Value

Type: System.IO.StreamReader
StreamReader object to read from the file


The file name ends with a backslash (\).


The specified file cannot be found.


The user lacks necessary permissions to read from the file.

Only text files can be read with a StreamReader.

The following table lists an example of a task involving the My.Computer.FileSystem.OpenTextFileReader method.

This example opens the file Testfile.txt, reads a line from it, and displays the line in a MessageBox.

Dim fileReader =
Dim stringReader = fileReader.ReadLine()
MsgBox("The first line of the file is " & stringReader)

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft