public static void Save(
DataTable dataTable,
string filePath,
char delimiter = ',',
IFormatProvider? formatProvider = null,
Encoding? textEncoding = null,
IEnumerable<string>? csvColumnNames = null,
string? format = null
)
Public Shared Sub Save (
dataTable As DataTable,
filePath As String,
Optional delimiter As Char = ","C,
Optional formatProvider As IFormatProvider = Nothing,
Optional textEncoding As Encoding = Nothing,
Optional csvColumnNames As IEnumerable(Of String) = Nothing,
Optional format As String = Nothing
)
public:
static void Save(
DataTable^ dataTable,
String^ filePath,
wchar_t delimiter = L',',
IFormatProvider^ formatProvider = nullptr,
Encoding^ textEncoding = nullptr,
IEnumerable<String^>^ csvColumnNames = nullptr,
String^ format = nullptr
)
static member Save :
dataTable : DataTable *
filePath : string *
?delimiter : char *
?formatProvider : IFormatProvider *
?textEncoding : Encoding *
?csvColumnNames : IEnumerable<string> *
?format : string
(* Defaults:
let _delimiter = defaultArg delimiter ','
let _formatProvider = defaultArg formatProvider null
let _textEncoding = defaultArg textEncoding null
let _csvColumnNames = defaultArg csvColumnNames null
let _format = defaultArg format null
*)
-> unit
The provider to use to format the value.
- or -
A null reference for InvariantCulture.
A collection of ColumnNames from dataTable that allows to select the DataColumns to export and to determine their order in the CSV file, or null to save the whole DataTable using its current column order.
Each item in this collection MUST be a ColumnName in dataTable.
A format String to use for all items that implement IFormattable.
- or -
A null reference to use the default format for each item.
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.
ArgumentNullException | dataTable or filePath is null. |
ArgumentException | filePath is not a valid file path. - or - csvColumnNames contains an item that is not a ColumnName in dataTable. |
ArgumentOutOfRangeException | delimiter is either the double quotes " or a line break character ('\r' or '\n'). |
IOException | I/O error. |