Class CsvFile
- Namespace
- SunamoCsv
- Assembly
- SunamoCsv.dll
Class to hold csv data Downloaded from http://www.codeproject.com/Articles/86973/C-CSV-Reader-and-Writer
public sealed class CsvFile
- Inheritance
-
CsvFile
- Inherited Members
- Extension Methods
Constructors
CsvFile()
Initializes a new instance of the CsvFile class
public CsvFile()
CsvFile(char)
Initializes a new instance of the CsvFile class with specified delimiter
public CsvFile(char delimiter)
Parameters
delimitercharCharacter to use as field delimiter
Fields
Headers
Gets the file headers
public readonly List<string> Headers
Field Value
Records
Gets the records in the file
public readonly CsvRecords Records
Field Value
Properties
HeaderCount
Gets the header count
public int HeaderCount { get; }
Property Value
this[int]
Gets a record at the specified index
public CsvRecord this[int recordIndex] { get; }
Parameters
recordIndexintRecord index
Property Value
- CsvRecord
CsvRecord
this[int, int]
Gets the field value at the specified record and field index
public string this[int recordIndex, int fieldIndex] { get; set; }
Parameters
Property Value
this[int, string]
Gets the field value at the specified record index for the supplied field name
public string this[int recordIndex, string fieldName] { get; set; }
Parameters
Property Value
RecordCount
Gets the record count
public int RecordCount { get; }
Property Value
Methods
DateTimes(int)
Return null when cannot be parsed
public List<DateTime?> DateTimes(int columnIndex)
Parameters
columnIndexint
Returns
Objects(params int[])
Returns values from specified columns as list of lists
public List<List<string>> Objects(params int[] columns)
Parameters
columnsint[]Array of zero-based column indices
Returns
Populate(bool, string)
Populates the current instance from a string
public void Populate(bool hasHeaderRow, string csvContent)
Parameters
Populate(bool, string, bool)
Populates the current instance from a string
public void Populate(bool hasHeaderRow, string csvContent, bool isTrimmingColumns)
Parameters
hasHeaderRowboolTrue if the file has a header row, otherwise false
csvContentstringCsv text
isTrimmingColumnsboolTrue if column values should be trimmed, otherwise false
Populate(bool, string, Encoding?, bool)
Populates the current instance from a string
public void Populate(bool hasHeaderRow, string csvContent, Encoding? encoding, bool isTrimmingColumns)
Parameters
hasHeaderRowboolTrue if the file has a header row, otherwise false
csvContentstringCsv text
encodingEncodingEncoding (null for UTF8)
isTrimmingColumnsboolTrue if column values should be trimmed, otherwise false
Populate(Stream, bool)
Populates the current instance from a stream
public void Populate(Stream stream, bool hasHeaderRow)
Parameters
Populate(Stream, bool, bool)
Populates the current instance from a stream
public void Populate(Stream stream, bool hasHeaderRow, bool isTrimmingColumns)
Parameters
streamStreamStream
hasHeaderRowboolTrue if the file has a header row, otherwise false
isTrimmingColumnsboolTrue if column values should be trimmed, otherwise false
Populate(Stream, Encoding?, bool, bool)
Populates the current instance from a stream
public void Populate(Stream stream, Encoding? encoding, bool hasHeaderRow, bool isTrimmingColumns)
Parameters
streamStreamStream
encodingEncodingEncoding (null for UTF8)
hasHeaderRowboolTrue if the file has a header row, otherwise false
isTrimmingColumnsboolTrue if column values should be trimmed, otherwise false
Populate(string, bool)
Populates the current instance from the specified file
public void Populate(string filePath, bool hasHeaderRow)
Parameters
Populate(string, bool, bool)
Populates the current instance from the specified file
public void Populate(string filePath, bool hasHeaderRow, bool isTrimmingColumns)
Parameters
filePathstringFile path
hasHeaderRowboolTrue if the file has a header row, otherwise false
isTrimmingColumnsboolTrue if column values should be trimmed, otherwise false
Populate(string, Encoding?, bool, bool)
Populates the current instance from the specified file
public void Populate(string filePath, Encoding? encoding, bool hasHeaderRow, bool isTrimmingColumns)
Parameters
filePathstringFile path
encodingEncodingEncoding (null for UTF8)
hasHeaderRowboolTrue if the file has a header row, otherwise false
isTrimmingColumnsboolTrue if column values should be trimmed, otherwise false
Strings(int)
Returns string values from specified column
public List<string> Strings(int columnIndex)
Parameters
columnIndexintZero-based column index