CsvConverterExtensionSaveCsvTSource(IEnumerableTSource, String, Int32, CsvFromTSource, Char, Encoding) Method

Saves a collection of TSource instances as a CSV file without header row.

Definition

Namespace: FolkerKinzel.CsvTools.Mappings
Assembly: FolkerKinzel.CsvTools.Mappings (in FolkerKinzel.CsvTools.Mappings.dll) Version: 1.1.0+1263e8243dc2cd78095f678f813d7d9c52ea4315
C#
public static void SaveCsv<TSource>(
	this IEnumerable<TSource> data,
	string filePath,
	int columnsCount,
	CsvFrom<TSource> converter,
	char delimiter = ',',
	Encoding? textEncoding = null
)

Parameters

data  IEnumerableTSource
The data to save as CSV file. Each item will be represented with a CSV row.
filePath  String
File path of the CSV file.
columnsCount  Int32
Number of columns in the CSV file.
converter  CsvFromTSource
An object that converts a TSource instance to a CSV row.
delimiter  Char  (Optional)
The field separator character.
textEncoding  Encoding  (Optional)
The text encoding to be used or null for UTF8.

Type Parameters

TSource
Generic type parameter for the data type to write as CSV row.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableTSource. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

Creates a new CSV file. If the target file already exists, it is truncated and overwritten.

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

Exceptions

ArgumentNullExceptionfilePath, or data, or converter is null.
ArgumentExceptionfilePath is not a valid file path.
ArgumentOutOfRangeExceptioncolumnsCount is negative.
IOExceptionI/O error.

See Also