question

titariko-7701 avatar image
0 Votes"
titariko-7701 asked titariko-7701 commented

What's the best way to parse a csv file and create entries in a webapi project?

I have a csv file with hundreds of rows with 5 columns. Ofc the 1st row consists of the column names while the rest of the rows are the data.
What is the best way to parse and create entries while at the same time excluding some of the data if they don't meet a certain condition?

Thank you

dotnet-csharp
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

NuGet has CSV parsers. The official docs cover reading a text file and looping over each line. Split the line by the comma and apply whatever validation logic you require.


0 Votes 0 ·

ok thanks, but where should the code for the parsing be written exactly?

0 Votes 0 ·

In Web API custom code runs within an action invoked from an HTTP method (GET POST etc) Typically, the parsing logic exists in a class or library. The Web API action calls the class or library to perform the task. I think you'll be interested in going through a few Getting Started tutorials found on this site.

https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-5.0&tabs=visual-studio
https://docs.microsoft.com/en-us/aspnet/core/web-api/?view=aspnetcore-5.0


1 Vote 1 ·
Show more comments

0 Answers