Upload
learningtech
View
79
Download
0
Tags:
Embed Size (px)
DESCRIPTION
linq tocsv by Jason
Citation preview
LINQ To CSVJason
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
LINQ To CSV -Quick Start
Reading from a file• Create a CsvFileDescription object
• Create a CsvContext object
Reading from a file• Read the file into an IEnumerable<T> using the CsvContext object's Read method
Writing to a file
• Create a CsvFileDescription object
• Create a CsvContext object
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
CsvContext.Read Overloads
CsvColumn Attribute• Name• CanBeNull• OutputFormat• FieldIndex
Name• Type• string
• Default• Name of the field or property
• Applies to• Reading and Writing
CanBeNull• Type• bool
• Default• true
• Applies to• Reading only
OutputFormat• Type• string
• Default• "G"
• Applies to• Writing only
FieldIndex• Type• Int
• Default• Int32.MaxValue
• Applies to• Reading and Writing
CsvFileDescription• SeparatorChar• QuoteAllFields• FirstLineHasColumnNames• TextEncoding• DetectEncodingFromByteOrderMarks• MaximumNbrExceptions
SeparatorChar• Type• char
• Default• ','
• Applies to• Reading and Writing
QuoteAllFields• Type• bool
• Default• false
• Applies to• Writing only
FirstLineHasColumnNames• Type• bool
• Default• true
• Applies to• Reading and Writing
EnforceCsvColumnAttribute• Type• bool
• Default• false
• Applies to• Reading and Writing
FileCultureName• Type• string
• Default• current system setting
• Applies to• Reading and Writing
TextEncoding• Type• Encoding
• Default• Encoding.UTF8
• Applies to• Reading and Writing
DetectEncodingFromByteOrderMarks
• Type• bool
• Default• true
• Applies to• Reading only
Reference• LINQ to CSV Library• http://www.codeproject.com/Articles/25133/LINQ-to-CSV-library