I have a list of string that I am writing out to a CSV file. I write this file like so:
FileInfo outputFile = new FileInfo("c:\output.csv");
StreamWriter writer = outputFile.CreateText();
StringBuilder line = new StringBuilder();
// List<String> listOfItems = ...
for (int i = 0, j = listOfItems.Count; i < j; i++) {
line.AppendFormat(" {0}", listOfItems[i]);
}
writer.WriteLine("col1,col2,{0}", line.ToString().Trim(' '));
writer.Close();
When I examine c:\output.csv
with tools like Notepad++ or enca the file looks to be plain text with a us-ascii encoding. But when my client uploads the CSV to their web store the column built with StringBuilder
is in the following format:
:VAL1 :VAL2 :VAL3 ... :VALN
That column should actually be:
val1 val2 val3 ... valN
Notice that the incorrect line has colons prefixed to each value, and the values have been uppercased.
The only thing I can figure is an encoding problem. So, what encoding would the above code generate?
Update (1 September 2010): Turned out to be a display bug in the remote web store. This code outputs plain text as it should.