Skip to content

Instantly share code, notes, and snippets.

@naveed-ahmad-biz
Created November 19, 2017 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naveed-ahmad-biz/51448c5b68569d038ad0c12fb523ab1d to your computer and use it in GitHub Desktop.
Save naveed-ahmad-biz/51448c5b68569d038ad0c12fb523ab1d to your computer and use it in GitHub Desktop.
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