22
LINQ To CSV Jason

20131108 linq tocsv by Jason

Embed Size (px)

DESCRIPTION

linq tocsv by Jason

Citation preview

Page 1: 20131108 linq tocsv by Jason

LINQ To CSVJason

Page 2: 20131108 linq tocsv by Jason

CSV• A comma-separated values (CSV) (also sometimes called character-separated values, because the separator character does not have to be a comma) file stores tabular data (numbers and text) in plain-text form

Page 3: 20131108 linq tocsv by Jason

LINQ To CSV -Quick Start

Page 4: 20131108 linq tocsv by Jason

Reading from a file• Create a CsvFileDescription object

• Create a CsvContext object

Page 5: 20131108 linq tocsv by Jason

Reading from a file• Read the file into an IEnumerable<T> using the CsvContext object's Read method

Page 6: 20131108 linq tocsv by Jason

Writing to a file

• Create a CsvFileDescription object

• Create a CsvContext object

Page 7: 20131108 linq tocsv by Jason

Writing to a file• Make sure the data is stored in an object that implements IEnumerable<T>

• Invoke the Write method exposed by the CsvContext object to write the contents of your IEnumerable<T> to a file

Page 8: 20131108 linq tocsv by Jason

CsvContext.Read Overloads

Page 10: 20131108 linq tocsv by Jason

Name• Type• string

• Default• Name of the field or property

• Applies to• Reading and Writing

Page 11: 20131108 linq tocsv by Jason

CanBeNull• Type• bool

• Default• true

• Applies to• Reading only

Page 12: 20131108 linq tocsv by Jason

OutputFormat• Type• string

• Default• "G"

• Applies to• Writing only

Page 13: 20131108 linq tocsv by Jason

FieldIndex• Type• Int

• Default• Int32.MaxValue

• Applies to• Reading and Writing

Page 15: 20131108 linq tocsv by Jason

SeparatorChar• Type• char

• Default• ','

• Applies to• Reading and Writing

Page 16: 20131108 linq tocsv by Jason

QuoteAllFields• Type• bool

• Default• false

• Applies to• Writing only

Page 17: 20131108 linq tocsv by Jason

FirstLineHasColumnNames• Type• bool

• Default• true

• Applies to• Reading and Writing

Page 18: 20131108 linq tocsv by Jason

EnforceCsvColumnAttribute• Type• bool

• Default• false

• Applies to• Reading and Writing

Page 19: 20131108 linq tocsv by Jason

FileCultureName• Type• string

• Default• current system setting

• Applies to• Reading and Writing

Page 20: 20131108 linq tocsv by Jason

TextEncoding• Type• Encoding

• Default• Encoding.UTF8

• Applies to• Reading and Writing

Page 21: 20131108 linq tocsv by Jason

DetectEncodingFromByteOrderMarks

• Type• bool

• Default• true

• Applies to• Reading only

Page 22: 20131108 linq tocsv by Jason

Reference• LINQ to CSV Library• http://www.codeproject.com/Articles/25133/LINQ-to-CSV-library