Try to search your question here, if you can't find : Ask Any Question Now ?

How to transform DataTable to CSV without Encoding Problem

HomeCategory: stackoverflowHow to transform DataTable to CSV without Encoding Problem
Avatarrupesh asked 6 days ago

I have a code about which transforms DataTable to CSV file. There is no problem about it. But when i look to CSV file some Turkish Characters (ISO-8859-9) seems wrong. I have to solve encoding problem;

StringBuilder sb = new StringBuilder();

        IEnumerable<string> columnNames = dt.Columns.Cast<DataColumn>().
                                          Select(column => column.ColumnName);
        sb.AppendLine(string.Join(",", columnNames));

        foreach (DataRow row in dt.Rows)
        {
            IEnumerable<string> fields = row.ItemArray.Select(field =>
              string.Concat(""", field.ToString().Replace(""", """"), """));
            sb.AppendLine(string.Join(",", fields));
        }

        File.WriteAllText("Gecisler" + Tarih + ".csv", sb.ToString());
1 Answers
Best Answer
AvatarAmit answered 6 days ago
Your Answer

11 + 17 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com