Я пытаюсь экспортировать данные в файл csv, так как в данных есть китайские символы, мне пришлось использовать юникод .. но после добавления преамбулы для юникода запятые не распознаются как разделители, и теперь все данные записываются в первый столбец. Я не уверен, что не так. Ниже мой код, который я написал в файле .ashx.
DataView priceQuery = (DataView)context.Session["priceQuery"];
String fundName = priceQuery.Table.Rows[0][0].ToString().Trim().Replace(' ', '_');
context.Response.Clear();
context.Response.ClearContent();
context.Response.ClearHeaders();
context.Response.ContentType = "text/csv";
context.Response.ContentEncoding = System.Text.Encoding.Unicode;
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + fundName + ".csv");
context.Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
String output = fundName + "\n";
output += "Price, Date" + "\n";
foreach (DataRow row in priceQuery.Table.Rows)
{
string price = row[2].ToString();
string date = ((DateTime)row[1]).ToString("dd-MMM-yy");
output += price + "," + date + "\n";
}
context.Response.Write(output);