20131108 linq tocsv by jason
DESCRIPTION
linq tocsv by JasonTRANSCRIPT
![Page 1: 20131108 linq tocsv by Jason](https://reader035.vdocuments.net/reader035/viewer/2022062708/5586b667d8b42a87178b4759/html5/thumbnails/1.jpg)
LINQ To CSVJason
![Page 2: 20131108 linq tocsv by Jason](https://reader035.vdocuments.net/reader035/viewer/2022062708/5586b667d8b42a87178b4759/html5/thumbnails/2.jpg)
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](https://reader035.vdocuments.net/reader035/viewer/2022062708/5586b667d8b42a87178b4759/html5/thumbnails/3.jpg)
LINQ To CSV -Quick Start
![Page 4: 20131108 linq tocsv by Jason](https://reader035.vdocuments.net/reader035/viewer/2022062708/5586b667d8b42a87178b4759/html5/thumbnails/4.jpg)
Reading from a file• Create a CsvFileDescription object
• Create a CsvContext object
![Page 5: 20131108 linq tocsv by Jason](https://reader035.vdocuments.net/reader035/viewer/2022062708/5586b667d8b42a87178b4759/html5/thumbnails/5.jpg)
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](https://reader035.vdocuments.net/reader035/viewer/2022062708/5586b667d8b42a87178b4759/html5/thumbnails/6.jpg)
Writing to a file
• Create a CsvFileDescription object
• Create a CsvContext object
![Page 7: 20131108 linq tocsv by Jason](https://reader035.vdocuments.net/reader035/viewer/2022062708/5586b667d8b42a87178b4759/html5/thumbnails/7.jpg)
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](https://reader035.vdocuments.net/reader035/viewer/2022062708/5586b667d8b42a87178b4759/html5/thumbnails/8.jpg)
CsvContext.Read Overloads
![Page 9: 20131108 linq tocsv by Jason](https://reader035.vdocuments.net/reader035/viewer/2022062708/5586b667d8b42a87178b4759/html5/thumbnails/9.jpg)
CsvColumn Attribute• Name• CanBeNull• OutputFormat• FieldIndex
![Page 10: 20131108 linq tocsv by Jason](https://reader035.vdocuments.net/reader035/viewer/2022062708/5586b667d8b42a87178b4759/html5/thumbnails/10.jpg)
Name• Type• string
• Default• Name of the field or property
• Applies to• Reading and Writing
![Page 11: 20131108 linq tocsv by Jason](https://reader035.vdocuments.net/reader035/viewer/2022062708/5586b667d8b42a87178b4759/html5/thumbnails/11.jpg)
CanBeNull• Type• bool
• Default• true
• Applies to• Reading only
![Page 12: 20131108 linq tocsv by Jason](https://reader035.vdocuments.net/reader035/viewer/2022062708/5586b667d8b42a87178b4759/html5/thumbnails/12.jpg)
OutputFormat• Type• string
• Default• "G"
• Applies to• Writing only
![Page 13: 20131108 linq tocsv by Jason](https://reader035.vdocuments.net/reader035/viewer/2022062708/5586b667d8b42a87178b4759/html5/thumbnails/13.jpg)
FieldIndex• Type• Int
• Default• Int32.MaxValue
• Applies to• Reading and Writing
![Page 14: 20131108 linq tocsv by Jason](https://reader035.vdocuments.net/reader035/viewer/2022062708/5586b667d8b42a87178b4759/html5/thumbnails/14.jpg)
CsvFileDescription• SeparatorChar• QuoteAllFields• FirstLineHasColumnNames• TextEncoding• DetectEncodingFromByteOrderMarks• MaximumNbrExceptions
![Page 15: 20131108 linq tocsv by Jason](https://reader035.vdocuments.net/reader035/viewer/2022062708/5586b667d8b42a87178b4759/html5/thumbnails/15.jpg)
SeparatorChar• Type• char
• Default• ','
• Applies to• Reading and Writing
![Page 16: 20131108 linq tocsv by Jason](https://reader035.vdocuments.net/reader035/viewer/2022062708/5586b667d8b42a87178b4759/html5/thumbnails/16.jpg)
QuoteAllFields• Type• bool
• Default• false
• Applies to• Writing only
![Page 17: 20131108 linq tocsv by Jason](https://reader035.vdocuments.net/reader035/viewer/2022062708/5586b667d8b42a87178b4759/html5/thumbnails/17.jpg)
FirstLineHasColumnNames• Type• bool
• Default• true
• Applies to• Reading and Writing
![Page 18: 20131108 linq tocsv by Jason](https://reader035.vdocuments.net/reader035/viewer/2022062708/5586b667d8b42a87178b4759/html5/thumbnails/18.jpg)
EnforceCsvColumnAttribute• Type• bool
• Default• false
• Applies to• Reading and Writing
![Page 19: 20131108 linq tocsv by Jason](https://reader035.vdocuments.net/reader035/viewer/2022062708/5586b667d8b42a87178b4759/html5/thumbnails/19.jpg)
FileCultureName• Type• string
• Default• current system setting
• Applies to• Reading and Writing
![Page 20: 20131108 linq tocsv by Jason](https://reader035.vdocuments.net/reader035/viewer/2022062708/5586b667d8b42a87178b4759/html5/thumbnails/20.jpg)
TextEncoding• Type• Encoding
• Default• Encoding.UTF8
• Applies to• Reading and Writing
![Page 21: 20131108 linq tocsv by Jason](https://reader035.vdocuments.net/reader035/viewer/2022062708/5586b667d8b42a87178b4759/html5/thumbnails/21.jpg)
DetectEncodingFromByteOrderMarks
• Type• bool
• Default• true
• Applies to• Reading only
![Page 22: 20131108 linq tocsv by Jason](https://reader035.vdocuments.net/reader035/viewer/2022062708/5586b667d8b42a87178b4759/html5/thumbnails/22.jpg)
Reference• LINQ to CSV Library• http://www.codeproject.com/Articles/25133/LINQ-to-CSV-library