Tuesday, July 18, 2017

Export CSV C#

//before your loop
    var csv = new StringBuilder();

//in your loop
    var first = reader[0].ToString();
    var second = image.ToString();
    //Suggestion made by KyleMit
    var newLine = string.Format("{0},{1}", first, second);
    csv.AppendLine(newLine);  

//after your loop
    File.WriteAllText(filePath, csv.ToString());
If you are using c# 6.0 then you can do the following
var newLine = $"{first},{second}"

No comments:
Write comments