Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

20131108 linq tocsv by Jason

262 views

Published on

linq tocsv by Jason

Published in: Technology, Education
  • Be the first to comment

  • Be the first to like this

20131108 linq tocsv by Jason

  1. 1. LINQ To CSV Jason
  2. 2. 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
  3. 3. LINQ To CSV -Quick Start
  4. 4. Reading from a file • Create a CsvFileDescription object • Create a CsvContext object
  5. 5. Reading from a file • Read the file into an IEnumerable<T> using the CsvContext object's Read method
  6. 6. Writing to a file • Create a CsvFileDescription object • Create a CsvContext object
  7. 7. 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
  8. 8. CsvContext.Read Overloads
  9. 9. CsvColumn Attribute • • • • Name CanBeNull OutputFormat FieldIndex
  10. 10. Name • Type • string • Default • Name of the field or property • Applies to • Reading and Writing
  11. 11. CanBeNull • Type • bool • Default • true • Applies to • Reading only
  12. 12. OutputFormat • Type • string • Default • "G" • Applies to • Writing only
  13. 13. FieldIndex • Type • Int • Default • Int32.MaxValue • Applies to • Reading and Writing
  14. 14. CsvFileDescription • • • • • • SeparatorChar QuoteAllFields FirstLineHasColumnNames TextEncoding DetectEncodingFromByteOrderMarks MaximumNbrExceptions
  15. 15. SeparatorChar • Type • char • Default • ',' • Applies to • Reading and Writing
  16. 16. QuoteAllFields • Type • bool • Default • false • Applies to • Writing only
  17. 17. FirstLineHasColumnNames • Type • bool • Default • true • Applies to • Reading and Writing
  18. 18. EnforceCsvColumnAttribute • Type • bool • Default • false • Applies to • Reading and Writing
  19. 19. FileCultureName • Type • string • Default • current system setting • Applies to • Reading and Writing
  20. 20. TextEncoding • Type • Encoding • Default • Encoding.UTF8 • Applies to • Reading and Writing
  21. 21. DetectEncodingFromByteOrderMarks • Type • bool • Default • true • Applies to • Reading only
  22. 22. Reference • LINQ to CSV Library • http://www.codeproject.com/Articles/25133/LINQ-to-CSV-library

×