I have multiple CSV files with each having only one work-sheet.
My task is to combine all the csvs into one sheet all have same data(number of columns and rows etc..,).
I have an System out of memory exception when the below situation rises.
I combine :
csv1,csv2,csv3,csv4,csv5 and generate a combines csvall.
now when I later try to combine csv6 with csvall it gives an system out of memory exception when the csvall file size is close to 100,000kb
HERE IS THE CODE:
if(txtConsolidated_OS_CSV.Text!=""){int counter =0;string[] files =(Directory.GetFiles(txtConsolidated_OS_CSV.Text.Trim()));foreach(var file in files){StringBuilder sb =newStringBuilder();string filename =Path.GetFileNameWithoutExtension(file);if(file.EndsWith(".csv")){string[] rows =File.ReadAllLines(file);for(int i =0; i < rows.Length; i++){if(i ==0){if(counter ==0){ sb.Append(rows[i]+"\n"); counter++;}}else{ sb.Append(rows[i]+"\n");}}}string csvfile = txtConsolidated_OS_CSV.Text+"\\Merged_OS.csv";if(File.Exists(csvfile)){File.AppendAllText(csvfile, sb.ToString()); sb.Clear();}else{File.WriteAllText(csvfile, sb.ToString()); sb.Clear();}//using (StreamWriter writer = new StreamWriter(csvfile, true))//{// writer.Write(sb.ToString());// writer.Dispose();// writer.Close();//}} counter =0;
Thank you in advance!
sudhansh