Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
private void ReadCSVFile(string fileName)
{
try
{
//file location, better to get it from configuration
string fileName = "C:\\temp\\MyProducts.csv";
//create a CSV engine using FileHelpers for your CSV file
var engine = new FileHelperEngine(typeof(MyProduct));
//read the CSV file into your object Arrary
var products = (MyProduct[])engine.ReadFile(fileName);
if (products.Any())
{
//process your records as per your requirements
foreach (var product in products)
{
//add it to your database, filter them etc
string name = product.Name
string description = product.Description
}
}
}
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.