I wanna make CSV file encoding UTF-8. Now, my CSV file cannot show Japanese Fonts. I want C# code to solve this problem.
StringBuilder sb = new StringBuilder();
var columnNames = dt.Columns.Cast().Select(column => column.ColumnName).ToArray();
sb.AppendLine(string.Join(",", columnNames));
foreach (DataRow row in dt.Rows)
{
var fields = row.ItemArray.Select(field => field.ToString()).ToArray();
sb.AppendLine(string.Join(",", fields));
}
File.WriteAllText(fileName, sb.ToString(), Encoding.UTF8);