我有一个用于将数据表转换为 csv 的 C# 代码。我的代码是
foreach (DataRow row in dt.Rows)
{
IEnumerable<string> fields = row.ItemArray.Select(field => field.ToString());
foreach (var item in fields)
{
sb.AppendFormat("\"{0}\",", item.Replace("\"", "\"\""));
}
sb = sb.Remove(sb.Length - 1, 1);
sb.Append("\n");
}
string attachment = "attachment; filename=mycsvfile.csv";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/csv";
Response.Write(sb.ToString());
Response.End();
有人知道如何将 csv 更改为 utf-8 吗?