简体   繁体   中英

How to apply validation on data stored in txt,csv,xls,xlsx file

I want to select the File(txt,csv,xls,xlsx) and then apply validation on the structure of the file. I have a DTO(Data Transfer Object) and want to validate the file using the DTO. For ex- DTO has three properties (Name,Class,Roll no) then the selected excel file should have the same columns.

You can't validate data when data is in the file(csv,txt...) .You must read data into computer memory,then through differrent metho to read data in different type of file.

For example,you can read txt File through File.ReadAllText,but you can't read Excel by the same way.

On my opinion,you can try...catch... wrap the read file code,if any exception is thrown,then file is not exactly what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM