CsvReader icon indicating copy to clipboard operation
CsvReader copied to clipboard

FieldCount not increased when Adding custom column

Open codermel opened this issue 6 years ago • 0 comments

While I can get this sample code to print out the value of my custom column correctly, it does not work with SBC. SBC will not see my new column.

Working sample code: ` using (StreamReader file = new StreamReader(_workingFile)) { using (CsvReader csv = new CsvReader(file, true, '\t')) { csv.GetFieldHeaders();

                csv.Columns.Add(new LumenWorks.Framework.IO.Csv.Column { Name = "Record_Date_UTC", Type = typeof(string) });
                csv.UseColumnDefaults = true;
                csv.Columns.Where(x => x.Name == "Record_Date_UTC").FirstOrDefault().DefaultValue = "Blah";
                int fieldCount = csv.FieldCount;
                fieldCount++; // Having to manually increase this by 1 to account for custom column

                string[] headers = csv.GetFieldHeaders();
                
                while (csv.ReadNextRecord())
                {
                    for (int i = 0; i < fieldCount; i++)
                        Console.Write(string.Format("{0} = {1};",
                                      headers[i], csv[i]));
                    Console.WriteLine();
                }
            }
        }

SBC code throws "System.ArgumentException: 'Record_Date_UTC' field header not found.":

                    using (CsvReader csv = new CsvReader(file, true, '\t'))
                    {
                        csv.GetFieldHeaders();
                        csv.Columns.Add(new LumenWorks.Framework.IO.Csv.Column { Name = "Record_Date_UTC", Type = typeof(DateTime) , DefaultValue = fileDate.ToShortDateString() });
                        csv.UseColumnDefaults = true;
                        var fieldCound = csv.FieldCount;

} `

codermel avatar Jul 10 '18 18:07 codermel