CsvWriter(String, IEnumerableString, Boolean, Char, Encoding) Constructor

Initializes a new CsvWriter object with the column names for the header row to be written.

Definition

Namespace: FolkerKinzel.CsvTools
Assembly: FolkerKinzel.CsvTools (in FolkerKinzel.CsvTools.dll) Version: 2.0.1+2345335399184346d9b2cc992ed5c814406052c1
C#
public CsvWriter(
	string filePath,
	IEnumerable<string?> columnNames,
	bool caseSensitive = false,
	char delimiter = ',',
	Encoding? textEncoding = null
)

Parameters

filePath  String
File path of the CSV file.
columnNames  IEnumerableString

A collection of column names for the header to be written.

The collection determines the order in which the columns appear in the CSV file and their index in CsvRecord. The CsvRecord instance, which the Record property of the newly initialized CsvWriter gets, can be accessed with this column names.

caseSensitive  Boolean  (Optional)
If true, column names that differ only in upper and lower case are also accepted, otherwise false.
delimiter  Char  (Optional)
The field separator character.
textEncoding  Encoding  (Optional)
The Encoding to be used or null for UTF8.

Remarks

The constructor creates a new file at the specified filePath. If the file already exists, it is truncated and overwritten.

Exceptions

ArgumentNullExceptionfilePath is null.
ArgumentException

filePath is not a valid file path

- or -

a column name in columnNames occurs twice. With caseSensitive can be chosen whether the comparison is case-sensitive or not.

ArgumentOutOfRangeExceptiondelimiter is either the double quotes " or a line break character ('\r' or '\n').
IOExceptionI/O error.

See Also