.NET C# 4.5.2 Library to Export Data in CSV File Format from C# List<AnyClassType>
public class SampleClass
{
public string ID {get;set;}
public string Name{get;set;}
public string Address{get;set;}
}
//Reference ExportCSV DLL in your references
using ExportCSV;
public void sampleMethod()
{
List<SampleClass> listObj = new List<SampleClass>();
listObj.Add(new SampleClass{ID=1,Name="Rishab Gupta",Address="Some Place, Delhi"});
listObj.Add(new SampleClass{ID=2,Name="Vibhor Agarwal",Address="Some New Place, Mumbai"});
}
ProcessDocument<SampleClass> objProcessDocument = new ProcessDocument<SampleClass>();
string outputString=string.Empty;
if you pass HttpContext object then Response.Write will happen resulting in ‘export to CSV’ Action
objProcessDocument(listObj, out outputString, HttpContext);
If you do not want to triger Response.Write() function and want to simply take the output to string (outputString) to handle in your own CSV (for example saving CSV outstring string to a database or StreamWriter) then you can pass null in place of the third variable.
objProcessDocument(listObj, out outputString); //Do not pass HttpContext to prevent trigger of Response.Write
Click here to visit GITHUB to see the Source Code