CsvAnalyzerAnalyzeFile Method

Analyzes the CSV file referenced by filePath to get the appropriate method arguments for parsing.

Definition

Namespace: FolkerKinzel.CsvTools
Assembly: FolkerKinzel.CsvTools (in FolkerKinzel.CsvTools.dll) Version: 2.0.1+2345335399184346d9b2cc992ed5c814406052c1
C#
public static CsvAnalyzerResult AnalyzeFile(
	string filePath,
	Encoding? textEncoding = null,
	Header header = Header.ProbablyPresent,
	int analyzedLines = 5
)

Parameters

filePath  String
File path of the CSV file.
textEncoding  Encoding  (Optional)

The text encoding to be used to read the CSV file, or null for UTF8.

header  Header  (Optional)
A supposition that is made about the presence of a header row.
analyzedLines  Int32  (Optional)
Maximum number of lines to analyze in the CSV file. The minimum value is AnalyzedLinesMinCount. If the file has fewer lines than analyzedLines, it will be analyzed completely. (You can specify Int32.MaxValue to analyze the entire file in any case.)

Return Value

CsvAnalyzerResult
The results of the analysis.

Remarks

CsvAnalyzer performs a statistical analysis on the CSV file to find the appropriate method arguments for reading the file. The result of the analysis is therefore always only an estimate, the accuracy of which increases with the number of lines analyzed. The analysis is time-consuming because the CSV file has to be accessed for reading.

The field delimiters COMMA (',', %x2C), SEMICOLON (';', %x3B), HASH ('#', %x23), TAB ('\t', %x09), and SPACE (' ', %x20) are recognized automatically.

Use AnalyzeFile(String, Encoding, Header, Int32) to analyze the textEncoding too.

Exceptions

ArgumentNullExceptionfilePath is null.
ArgumentOutOfRangeException

header is not a defined value of the Header enum.

- or -

header is a combination of Header values.

ArgumentExceptionfilePath is not a valid file path.
IOExceptionI/O error.

See Also