I have some .csv files which I am parsing before storing in database.
I would like to make application more robust, and perform validation upon the .csv files before
adrianm and Nipun Ambastha
Thank you for your response to my question.
I solved my problem by writing a solution to validate my .csv file myself.
It's quite possible a more elegant solution could be made by making use of adrianm's code, but I didn't do that, but I am encouraging to give adrianm's code a look.
I am validating the list below.
Empty file new FileInfo(dto.AbsoluteFileName).Length == 0
Wrong formatting of file lines. string[] items = line.Split('\t'); if (items.Count() == 20)
Wrong datatype in line fields. int number; bool isNumber = int.TryParse(dataRow.ItemArray[0].ToString(), out number);
Missing required line fields. if (dataRow.ItemArray[4].ToString().Length < 1)
To work through the contents of the .csv file I based my code on this code example:
http://bytes.com/topic/c-sharp/answers/256797-reading-tab-delimited-file