Skip to main content

Posts

Showing posts from May, 2010

Convert Generic List to CSV

In my recent development with c#, I have to code for the functionality to Convert one Generic list of class XYZ to CSV downloadable File with dynamically suppress some of the column and different descriptive headers then the properties name for the column. So I develop one Generic function which will convert List to CSV and return the string, which will then wrapped to Http Response to available as downloadable file. Here is a Function which will convert List of Generic type T to CVS format string with 2 arguments. First Argument is List of objects to be converted into CSV and second is the 2 dimensional string array with the name of properties of object to be include in conversion with the Header Text for that properties to use while it is converting into CSV. private static string ListToCsv( ref List <T> list, string [,] HeaderAndColumns)         {             if (list == null || list.Count == 0) return "" ;             Type t = typeof (T);             int