I am Using LumenWorks CsvReader for processing the CSV file. Currently i am doing validations for the CSV file where i need to throw error if the Header is empty for a field.
Example = Below is CSV file contents
Header 1,Header 2,Header 3 ,Header 4,Header 5,
Die 11,Die 22,Die 33,Die 44,Die 55,Test
Die 111,Die 222,Die 333,Die 444,Die 555,
Here "Test" is the extra field where Header does not exits. But i observed that CsvReader is adding a default header field called "Column5", instead of throwing error.
Here is the code snippet for reading and processing the CSV File.
//Read the CSV FIle
using (CsvReader csv = new CsvReader(new StreamReader(path), true))
{
//Set the missing Field Action.
csv.MissingFieldAction = MissingFieldAction.ParseError;
//Set Parse Action Error.
csv.DefaultParseErrorAction = ParseErrorAction.RaiseEvent;
csv.SkipEmptyLines = true;
int fieldCount = csv.FieldCount;
string[] headers = csv.GetFieldHeaders();
//Do the processing of the Data.
while (csv.ReadNextRecord())
{
XElement row = new XElement("KS");
for (int i = 0; i < fieldCount; i++)
{
XElement rowValue = new XElement("K");
XAttribute HeaderName = new XAttribute("N",
headers[i]);
XAttribute HeaderValue = new XAttribute("V", csv[i]);
rowValue.Add(HeaderName);
rowValue.Add(HeaderValue);
row.Add(rowValue);
}
root.Add(row);
}
}
}
I was expecting that an error should be thrown if there are fields with no headers, but it is adding "Column5". Is there any way where we can throw the error in LumenWorks CSV reader.
The following are the references which i tried to get
http://www.nudoq.org/#!/Packages/LumenWorks.Framework.IO/LumenWorks.Framework.IO/CsvReader
Thanks, Akshay