Export (0) Print
Expand All

FileSystemProxy.OpenTextFileReader Method (String)

Opens a StreamReader object to read from a file.

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

public StreamReader OpenTextFileReader(
	string file
)

Parameters

file
Type: System.String

File to be read.

Return Value

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

ExceptionCondition
ArgumentException

The file name ends with a backslash (\).

FileNotFoundException

The specified file cannot be found.

SecurityException

The user lacks necessary permissions to read from the file.

Only text files can be read with a StreamReader.

The following table lists examples of tasks 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 =
  My.Computer.FileSystem.OpenTextFileReader("C:\testfile.txt")
Dim stringReader = fileReader.ReadLine()
MsgBox("The first line of the file is " & stringReader)

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Show:
© 2015 Microsoft