Class CsvWriter
This class is used to create csv-files from System.Data.IDataReader or a System.Data.DataTable.
Inherited Members
Namespace: IRM.Data
Assembly: IRM.dll
Syntax
public class CsvWriter : WriterBase, IDisposable
Constructors
CsvWriter(Stream, CsvWriterOptions, Encoding)
Creates a CsvWriter object using a Stream to write data to.
Declaration
public CsvWriter(Stream outputStream, CsvWriterOptions options, Encoding encoding)
Parameters
System.IO.Stream
outputStream
The stream to write the column delimited data to. |
CsvWriterOptions
options
A CsvWriterOptions object defining how to handle writing the csv file. |
System.Text.Encoding
encoding
The System.Text.Encoding to use while writing the data. |
Exceptions
System.ArgumentNullException
|
CsvWriter(TextWriter, CsvWriterOptions)
Creates a CsvWriter object using a TextWriter to write data to.
Declaration
public CsvWriter(TextWriter outputStream, CsvWriterOptions options)
Parameters
System.IO.TextWriter
outputStream
The stream to write the column delimited data to. |
CsvWriterOptions
options
A CsvWriterOptions object defining how to handle writing the csv file. |
Exceptions
System.ArgumentNullException
|
CsvWriter(String)
Creates a CsvWriter object using a file to write data to. Uses a comma as the delimiter and Encoding.Default as the encoding.
Declaration
public CsvWriter(string fileName)
Parameters
String
fileName
The file to create with the column delimited data. |
Exceptions
System.ArgumentNullException
|
CsvWriter(String, CsvWriterOptions, Encoding)
Creates a CsvWriter object using a file to write data to.
Declaration
public CsvWriter(string fileName, CsvWriterOptions options, Encoding encoding)
Parameters
String
fileName
The file to create with the column delimited data. |
CsvWriterOptions
options
A CsvWriterOptions object defining how to handle writing the csv file. |
System.Text.Encoding
encoding
The System.Text.Encoding to use while writing the data. |
Exceptions
System.ArgumentNullException
|
Properties
Options
Gets or sets the options of how to handle writing the csv file.
Declaration
public CsvWriterOptions Options { get; }
Property Value
CsvWriterOptions
|
Methods
Dispose(Boolean)
Closes and releases all related resources.
Declaration
protected override void Dispose(bool disposing)
Parameters
Boolean
disposing
Whether this call is coming from an explicit call, instead of from the implicit GC finalizer call. |
Overrides
EndRecord(Boolean)
Ends the current record by sending the record delimiter.
Declaration
public void EndRecord(bool isHeaderRecord)
Parameters
Boolean
isHeaderRecord
|
Write(String, Boolean, Type)
Writes another column of data to this record.
Declaration
public void Write(string content, bool preserveSpaces, Type type)
Parameters
String
content
The data for the new column. |
Boolean
preserveSpaces
Whether to preserve leading and trailing whitespace in this column of data. |
System.Type
type
Type type of the |
Write(String, Type)
Writes another column of data to this record. Does not preserve leading and trailing whitespace in this column of data.
Declaration
public void Write(string content, Type type)
Parameters
String
content
The data for the new column. |
System.Type
type
The type of the |
WriteAll(DataTable)
Writes all data from the System.Data.DataTable. Writes the column name headers as the first record in the output data.
Declaration
public void WriteAll(DataTable data)
Parameters
System.Data.DataTable
data
The data to write to the output. |
WriteAll(DataTable, Boolean)
Writes all data from the System.Data.DataTable.
Declaration
public void WriteAll(DataTable data, bool writeHeaders)
Parameters
System.Data.DataTable
data
The data to write to the output. |
Boolean
writeHeaders
Write the column name headers as the first record in the output data. |
WriteAll(IDataReader)
Writes all data from the System.Data.IDataReader. Writes the column name headers as the first record in the output data.
Declaration
public void WriteAll(IDataReader reader)
Parameters
System.Data.IDataReader
reader
The input to write to the output. |
WriteAll(IDataReader, Boolean)
Writes all data from the System.Data.IDataReader.
Declaration
public void WriteAll(IDataReader reader, bool writeHeaders)
Parameters
System.Data.IDataReader
reader
The input to write to the output. |
Boolean
writeHeaders
Write the column name headers as the first record in the output data. |
WriteComment(String)
Writes comment text out to the file using the Comment character.
Declaration
public void WriteComment(string commentText)
Parameters
String
commentText
The text to write as a comment. |
WriteRecord(String[])
Writes a new record using the passed in array of values.
Declaration
public void WriteRecord(string[] values)
Parameters
String[]
values
Array of values to write in the record. |
WriteRecord(String[], Boolean)
Writes a new record using the passed in array of values.
Declaration
public void WriteRecord(string[] values, bool preserveSpaces)
Parameters
String[]
values
Array of values to write in the record. |
Boolean
preserveSpaces
Whether to preserver leading and trailing spaces in columns while writing out to the record or not. |