FileHelperEngineTReadFile Method (String, Int32) |
Read a file and return an array of the contained records.
Namespace:
FileHelpers
Assembly:
FileHelpers (in FileHelpers.dll) Version: 3.2.6
Syntaxpublic T[] ReadFile(
string fileName,
int maxRecords
)
Public Function ReadFile (
fileName As String,
maxRecords As Integer
) As T()
Parameters
- fileName
- Type: SystemString
The file path to be read. - maxRecords
- Type: SystemInt32
The max number of records to read. Int32.MaxValue or -1 to read all records.
Return Value
Type:
TAn array of the records in the file
Implements
IFileHelperEngineTReadFile(String, Int32)
Remarks
This method opens, reads and closes the file (don't open or close the file before or after calling this method)
Examples
This example shows a simple example of use of the library with a minimum of code:
using FileHelpers;
[Delimitedrecord("|")]
public class SampleType
{
public string Field1;
public int Field2;
}
public void ReadExample()
{
var engine = new FileHelperEngine<SampleType>();
var records = engine.ReadFile("source.txt");
int sum = records[0].Field2 + records[1].Field2;
}
See Also