Export (0) Print
Expand All

FileSystemProxy.OpenTextFieldParser Method (String)

The OpenTextFieldParser method allows you to create a TextFieldParser object, which provides a way to easily and efficiently parse structured text files, such as logs. The TextFieldParser object can be used to read both delimited and fixed-width files.

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

public TextFieldParser OpenTextFieldParser(
	string file


Type: System.String

The file to be opened with the TextFieldParser.

Return Value

Type: Microsoft.VisualBasic.FileIO.TextFieldParser
TextFieldParser to read the specified file.


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 \\.\); it ends with a trailing slash.


file is Nothing.


The file does not exist.


The file is in use by another process, or an I/O error occurs.


The path exceeds the system-defined maximum length.


A file or directory name in the path contains a colon (:) or is in an invalid format.


A row cannot be parsed using the specified format. The exception message specifies the line causing the exception, while the ErrorLine property is assigned the text contained in the line.


The user lacks necessary permissions to view the path.

The following table lists examples of tasks involving the My.Computer.FileSystem.OpenTextFieldParser method.

This example opens the TextFieldParser reader and uses it to read from C:\TestFolder1\Test1.txt.

Dim reader = My.Computer.FileSystem.OpenTextFieldParser(
reader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
reader.delimiters = {","}
Dim currentRow As String()
While Not reader.EndOfData
        currentRow = reader.ReadFields()
        Dim currentField As String 
        For Each currentField In currentRow
    Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
        MsgBox("Line " & ex.Message &
        "is not valid and will be skipped.")
    End Try 
End While

.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