CsvSave(IEnumerableIEnumerableObject, String, Char, IFormatProvider, Encoding, String) Method

Saves the contents of data as a CSV file.

Definition

Namespace: FolkerKinzel.CsvTools
Assembly: FolkerKinzel.CsvTools (in FolkerKinzel.CsvTools.dll) Version: 2.0.1+2345335399184346d9b2cc992ed5c814406052c1
C#
public static void Save(
	IEnumerable<IEnumerable<Object?>?> data,
	string filePath,
	char delimiter = ',',
	IFormatProvider? formatProvider = null,
	Encoding? textEncoding = null,
	string? format = null
)

Parameters

data  IEnumerableIEnumerableObject
The data to save.
filePath  String
File path of the CSV file.
delimiter  Char  (Optional)
The field separator character.
formatProvider  IFormatProvider  (Optional)

The provider to use to format the value.

- or -

A null reference for InvariantCulture.

textEncoding  Encoding  (Optional)
The Encoding to be used or null for UTF8.
format  String  (Optional)

A format String to use for all items that implement IFormattable.

- or -

A null reference to use the default format for each item.

Remarks

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

For serialization ToString(String, IFormatProvider) is used if the item implements IFormattable, otherwise ToString.

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

Exceptions

ArgumentNullExceptiondata or filePath 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