by David Kiff
23. December 2006 04:39
To add a header row to a CSV file I needed to append to the beginning of the text file, this however is not possible, instead I had to create a new file and write the original files contents to it after the header has been written:
StreamReader reader = new StreamReader(File.Open("Original.csv", FileMode.Open, FileAccess.Read));
StreamWriter writer = new StreamWriter(File.Create("Newfile.csv"));
writer.WriteLine("StudentID, Username, Forename, Surname"); //Write header row.
writer.WriteLine(reader.ReadToEnd()); //Write original file to the new one.
writer.Flush();
writer.Close();
reader.Close();
8a071195-d329-4df6-ba0e-45c09677598f|0|.0
Tags: