Using second row of file as header detail (ignore/delete first line)

Dec 19, 2012 at 4:02 PM

I'm trying to use KBCsv to manipulate bank statements details.

The csv file's first rows are full of garbage (thanks to the bank) which causes the following error when I try and process it. 

"Additional Information: A Record has 13 columns in it, but the header only defines 1"

Is there a way for KBCsv to ignore/delete the first row and use the second row as the header detail (and rest of the file as data)

Thanks

Martyn

Coordinator
Dec 19, 2012 at 6:26 PM

Hi Martyn,

Any reason you can't just discard the first row before KBCsv sees it? After all, KBCsv is a CSV reader - it can't be expected to work with non-conformant data.

using (TextReader textReader = ...)
{
    textReader.ReadLine();

    using (CsvReader csvReader = new CsvReader(textReader))
    {
        csvReader.ReadHeaderRecord();

        ...
    }
}

HTH,
Kent 

Dec 20, 2012 at 9:14 AM

Hi Kent

Thanks for your reply

I'm completely new to using CSVs (or any importing) in VB, so wouldn't know where to begin with discarding the first row before KBCsv sees it.

Any suggestions?

Coordinator
Dec 20, 2012 at 11:45 AM

Hi Martyn,

Please see the code sample in my previous answer. It basically throws away the first line of input before passing the reader onto KBCsv.

HTH,
Kent 

Dec 20, 2012 at 4:27 PM

Thanks for your help

I managed to use My.Computer.FileSystem.WriteAllText and  System.IO.File.AppendAllText to create a more KBCsv friendly CSV file.

Martyn