I want to write several csv lines into a csv file with StringBuilder. I enclose every field with quoation marks. If I export the file as a .txt I have excactly what I want ("Artist","Album","Track"). If I export as .csv the first field is not enclosed with quoation marks (Artist,"Album","Track"). Some test code that reproduces the issue:
static void Main(string[] args)
{
StringBuilder csv = new StringBuilder();
string artist = EncloseComma("Artist");
string album = EncloseComma("Album");
string track = EncloseComma("Track");
string newLine = string.Format("{0},{1},{2}", artist, album, track);
csv.AppendLine(newLine);
File.WriteAllText("test.csv", csv.ToString());
}
private static string EncloseComma(string str)
{
return "\"" + str + "\"";
}