TextFieldParser Constructor (Stream, Encoding, Boolean, Boolean)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Initializes a new instance of the TextFieldParser class.

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

Public Sub New (
	stream As Stream,
	defaultEncoding As Encoding,
	detectEncoding As Boolean,
	leaveOpen As Boolean


Type: System.IO.Stream

Stream. The stream to be parsed.

Type: System.Text.Encoding

Encoding. The character encoding to use if encoding is not determined from file. Default is UTF8.

Type: System.Boolean

Boolean. Indicates whether to look for byte order marks at the beginning of the file. Default is True.

Type: System.Boolean

Boolean. Indicates whether to leave stream open when the TextFieldParser object is closed. Default is False.

Exception Condition

stream or defaultEncoding is Nothing.


stream cannot be read from.

Creates a new TextFieldParser object to parse the file or stream that is represented by the stream parameter.

If the detectEncoding parameter is True, this constructor attempts to detect the encoding by looking at the first three bytes of the file or stream. It automatically recognizes UTF-8, little-endian Unicode, and big-endian Unicode text if the file starts with the appropriate byte-order marks. Otherwise, the encoding specified by defaultEncoding is used.


When you compile a set of characters with a particular cultural setting and retrieve those same characters with a different cultural setting, the characters might not be interpretable and could cause an exception to be thrown.

.NET Framework
Available since 2.0
Return to top