CSV is a common format for data exchange. It stands for “Comma Separated Values”. Values need to be double-quoted if they contain comma, double quotes, leading or trailing spaces. The format is actually quite simple. We can generate one easily with StringBuidler.
Product Model
Fake Product Data
CSV with StringBuilder
We can also generate a CSV file with FileHelpers library.
CSV with FileHelpers
FileHelpers is handy. We can install FileHelpers through Nuget Package Console. But when data gets complicated we may need to create a specific data model for it. For exaple, we may want to exclude PhotoUrl and ThumbnailUrl from the result. We can add FieldHidden annotations to hide them. But the annotation only supports fields, not properties.