A nifty export to CSV linq extension

Tags: export-to-csv, csv, linq, csharp

So I've been using this little gem of a code snippet in quite a few apps.

Nope, I didn't come up with it on my own, I got it from this blog article:
http://mikehadlow.blogspot.com/2008/06/linq-to-csv.html

I'm not sure what exactly wasn't working but I changed something I don't quite remember.

You use it like this:

IList<AnyTypeWithProperties> tableData = ...
tableData.AsCsv();//returns the data as csv in a string.

How-To:

Add a new file into visual studio, call it 'ExportToCsvExtension.cs' or anything you want. Remember an extension method must be defined on the TOP of its namespace.

Here is the code:

Enjoy!

Comments powered by Disqus