This documentation is archived and is not being maintained.

TextFieldParser.ErrorLineNumber Property

Returns the number of the line that caused the most recent MalformedLineException exception.

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

public long ErrorLineNumber { get; }

Property Value

Type: System.Int64
The number of the line that caused the most recent MalformedLineException exception.

If no MalformedLineException exceptions have been thrown, -1 is returned.

The ErrorLine property can be used to display the number of the line that caused the exception. Blank lines and comments are not ignored when determining the line number.

The following table lists examples of tasks involving the ErrorLineNumber property.

This example uses the ErrorLineNumber property to display the location of the line causing the current MalformedLineException exception.


Dim FileReader As Microsoft.VisualBasic.FileIO.TextFieldParser
FileReader = My.Computer.FileSystem.OpenTextFieldParser("C:\test.txt")
Dim currentRow As String()
While Not FileReader.EndOfData
    Try
        currentRow = FileReader.ReadFields
        For Each currentField As String In currentRow
            My.Computer.FileSystem.WriteAllText(
                "C://testfile.txt", currentField, True)
        Next
    Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
        MsgBox("Line " & FileReader.ErrorLineNumber & " is not valid.")
    End Try
End While


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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