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:

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.


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:


Comments powered by Disqus