Created
November 19, 2017 05:54
-
-
Save naveed-ahmad-biz/51448c5b68569d038ad0c12fb523ab1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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