CsvConverterOpenReadTResult(String, CsvToTResult, Char, Encoding, Boolean, CsvOpts) Method

Opens a CSV file for parsing its data.

Definition

Namespace: FolkerKinzel.CsvTools.Mappings
Assembly: FolkerKinzel.CsvTools.Mappings (in FolkerKinzel.CsvTools.Mappings.dll) Version: 1.1.0+1263e8243dc2cd78095f678f813d7d9c52ea4315
C#
public static CsvReader<TResult> OpenRead<TResult>(
	string filePath,
	CsvTo<TResult> converter,
	char delimiter = ',',
	Encoding? textEncoding = null,
	bool isHeaderPresent = true,
	CsvOpts options = CsvOpts.Default
)

Parameters

filePath  String
File path of the CSV file to read.
converter  CsvToTResult
An object that converts a CSV row to a TResult instance.
delimiter  Char  (Optional)
The field separator character.
textEncoding  Encoding  (Optional)
The text encoding to be used to read the CSV file or null for UTF8.
isHeaderPresent  Boolean  (Optional)
true, to interpret the first line as a header, otherwise false.
options  CsvOpts  (Optional)
Options for reading the CSV file.

Type Parameters

TResult
Generic type parameter that specifies the Type of the items that the CsvReaderTResult returns.

Return Value

CsvReaderTResult
A CsvReaderTResult that allows you to iterate through the data parsed from the CSV.

Remarks

The optimal parameters can be determined automatically with AnalyzeFile(String, Encoding, Header, Int32) - or use OpenReadAnalyzedTResult(String, CsvMapping, FuncObject, TResult, Encoding, Header, Int32).

When importing CSV data from Excel, the appropriate arguments can be determined with GetExcelArguments.

Exceptions

ArgumentNullExceptionfilePath or converter is null.
ArgumentExceptionfilePath is not a valid file path.
ArgumentOutOfRangeExceptiondelimiter is either the double quotes " or a line break character ('\r' or '\n').
IOExceptionI/O error.

See Also