Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 990923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:01:30+00:00 2026-05-16T06:01:30+00:00

I have the following PHP that reads in a CSV file and outputs rows/cells

  • 0

I have the following PHP that reads in a CSV file and outputs rows/cells of an HTML table. Can someone help me with an ASP.net equivalent?

<?php
$f = fopen("spreadsheet.csv", "r");
while (($line = fgetcsv($f)) !== false) {
    if(trim($line) != '' && $line != "\n" && $line != "\r") {
        echo '<tr>';
        foreach ($line as $cell) {
            echo "<td>" . htmlspecialchars($cell) . "</td>";
        }
        echo "</tr>\n";
    }
}
fclose($f);
?>

I see various options like http://github.com/claco/csvdatareader/ but being clueless about ASP.net, I’m afraid I don’t know how to make them work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:01:31+00:00Added an answer on May 16, 2026 at 6:01 am

    As demonstrated below there is no need to go outside of the .Net core framework to handle CSV files – Visual Basics TextFieldParser class will do it for you with out external dependencies. You can even use it in C#!

    StringBuilder MyTable = new StringBuilder();
    
    var Parser = new TextFieldParser(@"C:\Path\To\File\File.csv");
    Parser.HasFieldsEnclosedInQuotes = true;
    Parser.SetDelimiters(",");
    Parser.TextFieldType = FieldType.Delimited;
    MyTable.AppendLine("<table>");
    
    while(var Row = Parser.ReadFields()) 
    {
        MyTable.AppendLine("<tr>");
    
        foreach(var Field in Row)
        {
            MyTable.AppendLine("<td>" + Field + "</td>");
        }
    
        Mytable.AppendLine("</tr>");
    }
    
    MyTable.AppendLine("</table>");
    

    There is probably a few minor things wrong with the above, I’m doing it on the fly and very quickly 🙂 It should be largely correct however – its a fairly OK code sample for an introduction, personally I wouldnt build the table myself but I would create a datasource (read the csv file into a datatable perhaps), and bind that to an ASP.Net control (HtmlTable or Gridview) which will build the html for us.

    But in this case, its a nice example giving you exactly what you had in PHP.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP file that reads in a CSV file and stores the
I have the following situation. I have a PHP script that imports a CSV
In PHP I have the following code that gets a file submitted through CGI:
This is for MySQL and PHP I have a table that contains the following
I have the following MYSQL select statement in a php file that was provided
I have a PHP script that does the following: Uses file_get_contents() to get content
I have a line of PHP code that does the following: $xml = <xml><request>...[snipped
I have code that looks like the following: <form id=MyForm name=MyForm method=post action=index.php> <input
In a php file i have used include to include the following js.php file
I have a jquery script that searches a php file that produces an XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.