Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
private void WriteCSVFile(List<SomeDataSource> dataSource)
{
try
{
//filehelper object
FileHelperEngine engine = new FileHelperEngine(typeof(MyProdcuts));
//csv object
List<MyProduct> csv = new List<MyProduct>();
//convert any datasource to csv based object
foreach (var item in dataSource)
{
MyProduct temp = new MyProduct();
temp.Name = item.Name;
temp.Description = item.Description
csv.Add(temp);
}
//give file a name and header text
string filename = "MyProducts.csv";
engine.HeaderText = "Name,Description";
//save file locally
engine.WriteFile(Server.MapPath(filename),csv);
}
catch (Exception ex)
{
LogException(ex);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.