I’ve created a ASP.Net Core Web API in C# using the .Net 8.0 Framework. It calls a command line utility, saves the output in a csv file, then formats that file as needed. I’ve already got a simple webpage where users can call the API, but I also want to read that csv file and display the contents to the webpage in a tabular format once the API is done running.
This is a sample from the csv file, and I want the data to look exactly like this on my webpage:
CSV File
My first “solution” to read the file and display the data onto my webpage was very manual, and not something I want to pursue. I made a file input type for users to select the csv file.
Here is the Javascript I used:
document.getElementById('inputFile').addEventListener('change', function(){
let fr = new FileReader();
fr.onload = function () {
document.getElementById('output').textContent = fr.result;
}
fr.readAsText(this.files[0]);
})
And a sample of what was output to the webpage
Product Description Licenses Available Licenses In Use UserID Host Start_Date
NX Mach 3 Ind Design 39 licenses issued 3 licenses in use
ab012 TXABCCKLNWK8 Thu|2/22|23:30
jsimmons AG813341 Wed|2/28|5:12
abr01 TXABC297Q9W2 Wed|2/28|7:16
NX Mach 1 Design (Floating) 18 licenses issued 2 licenses in use
ab00001 TXABCCL18LQ6 Tue|2/27|0:22
jjameson AG815086 Wed|2/28|11:00
Does anyone have any ideas on how I can read in the csv file after the API is done running, and dynamically have the data fill in a table using Javascript?