public static void ReadCsvAnalyzed(
this DataTable dataTable,
string filePath,
CsvMapping mapping,
Encoding? defaultEncoding = null,
Header header = Header.ProbablyPresent,
int analyzedLines = 5
)
<ExtensionAttribute>
Public Shared Sub ReadCsvAnalyzed (
dataTable As DataTable,
filePath As String,
mapping As CsvMapping,
Optional defaultEncoding As Encoding = Nothing,
Optional header As Header = Header.ProbablyPresent,
Optional analyzedLines As Integer = 5
)
public:
[ExtensionAttribute]
static void ReadCsvAnalyzed(
DataTable^ dataTable,
String^ filePath,
CsvMapping^ mapping,
Encoding^ defaultEncoding = nullptr,
Header header = Header::ProbablyPresent,
int analyzedLines = 5
)
[<ExtensionAttribute>]
static member ReadCsvAnalyzed :
dataTable : DataTable *
filePath : string *
mapping : CsvMapping *
?defaultEncoding : Encoding *
?header : Header *
?analyzedLines : int
(* Defaults:
let _defaultEncoding = defaultArg defaultEncoding null
let _header = defaultArg header Header.ProbablyPresent
let _analyzedLines = defaultArg analyzedLines 5
*)
-> unit
Each PropertyName of mapping MUST have a corresponding DataColumn in dataTable - corresponding in the Caption property (case-insensitive) and the accepted data type.
Effort must be taken that the PropertyNames in mapping are unique, even when treated case-insensitive.
The DynamicProperty instances in mapping don't need to match all columns of the DataTable or all columns of the CSV file (neither in number nor in order).
The method performs a statistical analysis on the CSV file to find the appropriate parameters 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.
This method also tries to determine the Encoding of the CSV file from the byte order mark (BOM). If no byte order mark can be found, defaultEncoding is used.
ArgumentNullException | dataTable, or filePath, or mapping is null. |
ArgumentException | filePath is not a valid file path. - or - There is a DynamicProperty in mapping whose PropertyName finds no corresponding ColumnName in dataTable. |
FormatException | Parsing fails and Throwing is true. |
NoNullAllowedException | The mapping doesn't match the schema of the dataTable. |
ConstraintException | The parsed CSV data does not match the schema of the dataTable. |
IOException | I/O error. |
ObjectDisposedException | The file was already closed. |