I need to split large CSV files by the source field and name the export files the name as the source field.
My code works, but the only thing that's not working is I need the split files to have the header row from the original file.
Any help is appreciated. Thank you.
var splitQuery = from line in File.ReadLines(@"C:\test\test1.csv")
let source = line.Split(',').Last()
group line by source into outputs
select outputs;
foreach (var output in splitQuery)
{
File.WriteAllLines(@"C:\test\" + output.Key + ".csv", output);
}
Im not sure how to add a snippet of the CSV but ive put a snippet of the header fields, hope this helps
ID ,Ref ,Title ,Initials ,Forename ,Surname ,File_Source
test1.csvhave the headers in the first line of the file?