0

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?

Vian Ojeda Garcia
  • 827
  • 4
  • 17
  • 34
  • 1
    Does this answer your question? [C# FileStream read set encoding](https://stackoverflow.com/questions/40791109/c-sharp-filestream-read-set-encoding) – Selim Yildiz Feb 19 '20 at 05:50
  • Is your source file encoded in UTF-8? Open it with texteditor like notepad++ to check. This link might help: https://stackoverflow.com/questions/48574894/importing-utf-8-encoded-csv-in-meteor-using-papa-parse – Louis Go Feb 19 '20 at 05:51
  • @LouisGo its in a csv file and It stores the data correctly – Vian Ojeda Garcia Feb 19 '20 at 05:56
  • @SelimYıldız it crossed my mind but the Papa.parse accept `Stream,String,URI` how can I make that work im sorry – Vian Ojeda Garcia Feb 19 '20 at 05:57

0 Answers0