csvhelper

CSVHelper to skip record before header

懵懂的女人 提交于 2021-02-19 05:27:07
问题 I have data in a file in following format. HEADER|ReportItem Name: Margin Ri..... Account Id/Margin Id|Account Name|Ba...... // the row with headers Data row 1 Data row 2 TRAILER|Record Count: 2 This is throwing an error - I believe due to fact there is a that row before the actual reader row. using (var textReader = File.OpenText(path)) { var csv = new CsvReader(textReader); csv.Configuration.RegisterClassMap<GsClassMap>(); csv.Configuration.TrimOptions = TrimOptions.Trim; csv.Configuration

CSVHelper to skip record before header

笑着哭i 提交于 2021-02-19 05:25:38
问题 I have data in a file in following format. HEADER|ReportItem Name: Margin Ri..... Account Id/Margin Id|Account Name|Ba...... // the row with headers Data row 1 Data row 2 TRAILER|Record Count: 2 This is throwing an error - I believe due to fact there is a that row before the actual reader row. using (var textReader = File.OpenText(path)) { var csv = new CsvReader(textReader); csv.Configuration.RegisterClassMap<GsClassMap>(); csv.Configuration.TrimOptions = TrimOptions.Trim; csv.Configuration

When uploading memory stream with contents created by csvhelper using SSH.NET to SFTP server, the uploaded file is empty

一世执手 提交于 2021-02-08 07:28:31
问题 I'm truing to send a CSV with csvhelper. But when I send it, it is always empty. using (var sftProvider =new SFTProvider(Configuration)) using (var csvProvider=new CSVProvider(Configuration)) using (Stream fileStream = new MemoryStream()) { var sftp = sftProvider.SFTPConnection("", "", ""); var nameFile = "/ethias/"+DateTime.Now.ToString(DateFormatConstants.DATE_FORMAT) + ".csv"; if (sftp.Exists(nameFile)) { sftProvider.ReadFileSFTP(sftp, nameFile, fileStream); } await csvProvider.WriteCsv

NullValues Option Not Working When Loading to DataTable

与世无争的帅哥 提交于 2021-02-07 10:30:15
问题 When reading a CSV into a DataTable, I am trying to add options for boolean and null values that don't seem to be working. For example, a file containing data similar to: Id,MaxDiscount,Name,Active,AltId 1,,Foo,1,ABC123 2,10,Bar,0,DEF345 And the following logic that uses a schema file to dynamically get the headers and data types we are expecting: var dt = new DataTable(); using (var reader = new StreamReader(file.FullName)) using (var csv = new CsvReader(reader)) { csv.Configuration

NullValues Option Not Working When Loading to DataTable

筅森魡賤 提交于 2021-02-07 10:28:12
问题 When reading a CSV into a DataTable, I am trying to add options for boolean and null values that don't seem to be working. For example, a file containing data similar to: Id,MaxDiscount,Name,Active,AltId 1,,Foo,1,ABC123 2,10,Bar,0,DEF345 And the following logic that uses a schema file to dynamically get the headers and data types we are expecting: var dt = new DataTable(); using (var reader = new StreamReader(file.FullName)) using (var csv = new CsvReader(reader)) { csv.Configuration

How to write IList<T> to csv file using CsvHelper?

霸气de小男生 提交于 2021-01-29 04:24:27
问题 I just started playing with the CsvHelper component by Josh Close. But I haven't yet fully understood the concept of mapping. What I have is a class Order that looks like this: public class Order { public int Id { get; set; } public IList<Address> Addresses { get; set; } } where Address looks like this: public class Address { public string Name { get; set; } public string City { get; set; } } Now I'd like to write these classes to a csv file. Sample output could be something like this: Order

Parse csv to decimal on different cultures using CsvHelper in c#

时光毁灭记忆、已成空白 提交于 2021-01-28 14:23:42
问题 Problem with parsing decimals by CsvHelper in c#. I created a class that get csv file from byte[] istead of file, and it works correctly. public static List<Topic> GetAll(byte[] attachmentBytes) { using (Stream stream = new MemoryStream(attachmentBytes)) { using (var reader = new StreamReader(stream, Encoding.GetEncoding(1252), true)) { using (var csv = new CsvReader(reader)) { csv.Configuration.Delimiter = ";"; csv.Configuration.HasHeaderRecord = true; csv.Configuration.CultureInfo =

CSVHelper BadDataFound in a valid csv

霸气de小男生 提交于 2021-01-28 07:30:36
问题 Our customer started reporting bugs with importing data from CSV file. After seeing the csv file, we decided to switch from custom CSV parser to CSVHelper, but the CSV Helper can't read some valid CSV files. The users are able to load any csv file into our application, so we can't use any class mapper. We use csv.Parser.Read to read string[] dataRows. We can't change a way how this csv file is generated, it is generated by another company and we can't convince them to change the generation

CsvHelper Error “No header record found” on reading a csv stream

无人久伴 提交于 2021-01-07 02:43:10
问题 Below is the code which i using to read a stream source of csv files but I get error as "No header record found". The library is 15.0 and I am already using .ToList() as suggested in some solutions, but still the error persists. Below is the method along with the tablefield class and the Read Stream method. Also note here, I can get the desired result if I pass source as MemoryStream but it fails if I pass it as Stream because I need to avoid writing to memory each time. public async Task

CsvHelper Error “No header record found” on reading a csv stream

三世轮回 提交于 2021-01-07 02:42:33
问题 Below is the code which i using to read a stream source of csv files but I get error as "No header record found". The library is 15.0 and I am already using .ToList() as suggested in some solutions, but still the error persists. Below is the method along with the tablefield class and the Read Stream method. Also note here, I can get the desired result if I pass source as MemoryStream but it fails if I pass it as Stream because I need to avoid writing to memory each time. public async Task