I am using papa parse as csv parser for my data but I can't convert the data to UTF-8
string name = dataitem.Headers.ContentDisposition.FileName.Replace("\"", "");
string newFileName = Guid.NewGuid() + Path.GetExtension(name);
File.Move(dataitem.LocalFileName, Path.Combine(rootPath, newFileName));
List<JObject> rows = new List<JObject>();
using (FileStream stream = File.OpenRead(Path.Combine(rootPath, newFileName)))
{
Papa.parse(stream, new Config()
{
header = true,
skipEmptyLines = true,
encoding = Encoding.UTF8,
complete = parsed =>
{
foreach (JObject jo in JArray.Parse(parsed.dataWithHeader.DumpAsJson()))
rows.Add(jo);
var dt = new DataTable();
dt.Columns.Add("data");
foreach (object jo in rows)
dt.Rows.Add(jo.ToString());
if (result.Rows[0]["Result"].ToString() == "False")
{
throw new Exception(result.Rows[0]["Message"].ToString());
}
}
});
}
File.Delete(Path.Combine(rootPath, newFileName));
Upon checking when the Papaparse
parse the data. It produces the wrong data from Evelyn N Baliño
to Evelyn N Bali�o
but I already change the encoding to UTF8. What am I doing wrong? should I specify the encoding in the FileStream
?