private static void SetSalesFileEncoding(CSVSalesFile salesFile) { Encoding encoding = Encoding.GetEncoding("iso-8859-1"); Encoding utf8 = Encoding.UTF8; byte[] utfBytes = utf8.GetBytes(salesFile.FileContent); byte[] isoBytes = Encoding.Convert(utf8, encoding, utfBytes); salesFile.FileContent = encoding.GetString(isoBytes); }
public SalesFileBase CreateSalesFile(IFormFile formFile, DateTime uploadedDateTime) { string extension = Path.GetExtension(formFile.FileName); switch (extension) { case ".csv": { string fileContent = ReadContentFromIFormFile(formFile); var salesFile = new CSVSalesFile(fileContent, uploadedDateTime, $"{GenerateFileName(uploadedDateTime)}.csv"); SetSalesFileEncoding(salesFile); return(salesFile); } default: throw new ApplicationException("Uploaded file type does not supported"); } }