weixin_39630048
weixin_39630048
2021-01-08 01:32

Validate csv file

Hello,

Maybe this is a feature request. Is it possible to validate a csv file with a simple statement? Like:


csvReader = new CsvReader(textReader);
// [Omitted Configuration settings]
var validationResult = csvReader.Validate();
return validationResult.IsValid;

With kind regards,

Cees van Altena

该提问来源于开源项目:JoshClose/CsvHelper

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

8条回答

  • weixin_39787792 weixin_39787792 4月前

    You could just do a try catch on GetRecords()

    On Mar 16, 2017 5:45 AM, "Cees van Altena" wrote:

    Hello,

    Maybe this is a feature request. Is it possible to validate a csv file with a simple statement? Like:

    csvReader = new CsvReader(textReader); // [Omitted Configuration settings] var validationResult = csvReader.Validate(); return validationResult.IsValid;

    With kind regards,

    Cees van Altena

    — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/JoshClose/CsvHelper/issues/657, or mute the thread https://github.com/notifications/unsubscribe-auth/AD_ohaOoH3Z6dkRXytAP5Dia8x3hC4TLks5rmQS-gaJpZM4MfDV4 .

    点赞 评论 复制链接分享
  • weixin_39630048 weixin_39630048 4月前

    Thank you for the fast reply!

    You could just do a try catch on GetRecords()

    It is something but I would like to call this a work-around. For the user it is better to use a Validate() method or something like that because when you advise another way to validate, we developers have to change our code.

    Please also add the work-around to the docs.

    With kind regards,

    点赞 评论 复制链接分享
  • weixin_39768645 weixin_39768645 4月前

    What would it be validating?

    点赞 评论 复制链接分享
  • weixin_39630048 weixin_39630048 4月前

    Hmm good one. If the string/file/stream is in a CSV format?

    点赞 评论 复制链接分享
  • weixin_39768645 weixin_39768645 4月前

    I'm not even sure if that's possible. Worst case scenario is the entire file is one row with a single field.

    There is some bad field detection happening currently. There are config options for ThrowOnBadData and BadDataCallback that can be used.

    点赞 评论 复制链接分享
  • weixin_39768645 weixin_39768645 4月前

    I'm going to close this for now. If you can think of a way to validate a file I'll look into. The issue is a bad formatted file could like a file with a single row and field, and that's valid.

    点赞 评论 复制链接分享
  • weixin_39630048 weixin_39630048 4月前

    I'm going to close this for now. If you can think of a way to validate a file I'll look into. The issue is a bad formatted file could like a file with a single row and field, and that's valid.

    No problem, sorry for not responding.

    点赞 评论 复制链接分享
  • weixin_39882271 weixin_39882271 4月前

    +1 for this feature

    点赞 评论 复制链接分享

相关推荐