IRONSOFTWAREHOME

Read a CSV File in C#

Curtis Chau
Curtis Chau
Updated: July 21, 2026

IronXL provides a one-line solution to read CSV files in C# using the LoadCSV method. It supports custom delimiters and direct conversion to Excel formats for seamless data processing in .NET applications.

Quickstart: Load and convert a CSV file using IronXL in one line

This example shows how to read a CSV file using IronXL's LoadCSV method and save it as an Excel workbook with minimal code.

  1. 1Install IronXL with NuGet Package Manager

    PM > Install-Package IronXL.Excel

  2. 2Copy and run this code snippet.

    WorkBook wb = WorkBook.LoadCSV("data.csv", ExcelFileFormat.XLSX, listDelimiter: ","); wb.SaveAs("output.xlsx");
    C#
  3. 3Deploy to test on your live environment

    Start using IronXL in your project today with a free trial
    arrow pointer

Reading CSV Files in .NET Applications

  • Install a C# library for Reading CSV Files (IronXL)
  • Read CSV files in C#
  • Specify file format and delimiter

Step 1

How Do I Install the IronXL Library?

Before using IronXL to read CSV files in MVC, ASP, or .NET Core, you need to install it. Here's a quick walkthrough.

Why Should I Use NuGet Package Manager?

  • In Visual Studio, select the Project menu
  • Manage NuGet Packages
  • Search for IronXL.Excel
  • Install
Visual Studio NuGet Package Manager installing IronXL.Excel library with package details and console output

Figure 1

IronXL.Excel NuGet Package

What Are Alternative Installation Methods?

Or download from the Iron Software website: https://ironsoftware.com/csharp/excel/packages/IronXL.zip

For .NET developers working with Docker containers, IronXL can be configured in your Docker environment. The library also supports deployment on Azure Functions and AWS Lambda for cloud-based CSV processing.


How to Tutorial

How Do I Read CSV Files Programmatically?

Now for the project!

What Namespace Do I Need to Import?

Add the IronXL namespace:

// This namespace is required to access the IronXL functionalities
using IronXL;

How Do I Load and Convert CSV Files?

Add code to read a CSV file programmatically with IronXL and C#:

// Load the CSV file into a WorkBook object, specifying the file path, format, and delimiter
WorkBook workbook = WorkBook.LoadCSV("Read_CSV_Ex.csv", fileFormat: ExcelFileFormat.XLSX, listDelimiter: ",");

// Access the default worksheet within the loaded workbook
WorkSheet ws = workbook.DefaultWorkSheet;

// Save the workbook as an Excel file with a specified name
workbook.SaveAs("Csv_To_Excel.xlsx");

What Advanced CSV Reading Options Are Available?

IronXL provides features for handling CSV files with various configurations. You can specify different delimiters (semicolons, tabs, pipes) and handle files with different encodings:

// Example: Reading CSV with custom delimiter
WorkBook workbook = WorkBook.LoadCSV("data.csv",
    fileFormat: ExcelFileFormat.XLSX,
    listDelimiter: ";");  // Using semicolon as delimiter

// Access specific cells after loading
var cellValue = workbook.DefaultWorkSheet["A1"].Value;

// Iterate through rows
foreach (var row in workbook.DefaultWorkSheet.Rows)
{
    // Process each row
    foreach (var cell in row)
    {
        Console.WriteLine(cell.Value);
    }
}
C#

What Does the CSV File Look Like Before Processing?

CSV file in Notepad showing animal data with Month, Giraffes, Elephants, Rhinos columns and 6 months of population data

Figure 2

A CSV file opened in Notepad

How Does LoadCSV Method Work?

A Workbook object is created. The LoadCSV method of the Workbook object specifies the CSV file to read, the format to read it into, and the delimiter. In this case, a comma is used as a separator.

A Worksheet object is created where the CSV contents are placed. The file is then saved under a new name and format. This process is useful when you need to convert between different spreadsheet formats.

Excel spreadsheet showing CSV data with columns for Month, Giraffes, Elephants, and Rhinos with 6 months of animal count data

Figure 3

The CSV file opened in Excel

Can I Process Large CSV Files Efficiently?

IronXL is optimized for performance and handles large CSV files efficiently. For developers working with substantial datasets, the library offers significant performance improvements in recent versions. When processing large files, consider these best practices:

// Reading large CSV files with memory optimization
WorkBook workbook = WorkBook.LoadCSV("large_dataset.csv", 
    fileFormat: ExcelFileFormat.XLSX, 
    listDelimiter: ",");

// Process data in chunks
var worksheet = workbook.DefaultWorkSheet;
int rowCount = worksheet.RowCount;
int batchSize = 1000;

for (int i = 0; i < rowCount; i += batchSize)
{
    // Process rows in batches
    var endIndex = Math.Min(i + batchSize, rowCount);
    for (int j = i; j < endIndex; j++)
    {
        var row = worksheet.GetRow(j);
        // Process individual row
    }
}

How Can I Export CSV Data to Other Formats?

After reading CSV files, you might need to export the data to various formats. IronXL supports multiple export options including XLSX to CSV conversion, JSON, XML, and HTML. Here's how to export to different formats:

// Load CSV and export to multiple formats
WorkBook workbook = WorkBook.LoadCSV("input.csv", ExcelFileFormat.XLSX, ",");

// Export to different formats
workbook.SaveAs("output.xlsx"); // Excel format
workbook.SaveAsJson("output.json"); // JSON format
workbook.SaveAsXml("output.xml"); // XML format

// Export specific worksheet to CSV with custom delimiter
workbook.DefaultWorkSheet.SaveAsCsv("output_custom.csv", ";");
C#

What About Working with CSV Data in Web Applications?

For ASP.NET developers, IronXL provides seamless integration for reading CSV files in web applications. You can upload and process CSV files in your MVC or Web API projects:

// Example: Processing uploaded CSV file in ASP.NET
public ActionResult UploadCSV(HttpPostedFileBase file)
{
    if (file != null && file.ContentLength > 0)
    {
        // Save uploaded file temporarily
        var fileName = Path.GetFileName(file.FileName);
        var path = Path.Combine(Server.MapPath("~/App_Data/"), fileName);
        file.SaveAs(path);
        
        // Load and process CSV
        WorkBook workbook = WorkBook.LoadCSV(path, ExcelFileFormat.XLSX, ",");
        
        // Convert to DataTable for easy display
        var dataTable = workbook.DefaultWorkSheet.ToDataTable();
        
        // Clean up temporary file
        System.IO.File.Delete(path);
        
        return View(dataTable);
    }
    return RedirectToAction("Index");
}

How Do I Handle CSV Files with Complex Data?

When working with CSV files containing formulas, special characters, or mixed data types, IronXL provides robust handling capabilities. You can work with formulas and format cell data appropriately:

// Handle CSV with special requirements
WorkBook workbook = WorkBook.LoadCSV("complex_data.csv", 
    ExcelFileFormat.XLSX, 
    listDelimiter: ",");

var worksheet = workbook.DefaultWorkSheet;

// Apply formatting to cells
worksheet["A1:A10"].Style.Font.Bold = true;
worksheet["B1:B10"].FormatString = "$#,##0.00"; // Currency format

// Add formulas after loading CSV data
worksheet["D1"].Formula = "=SUM(B1:B10)";

Library Quick Access

IronXL API Reference Documentation

Learn more and share how to merge, unmerge, and work with cells in Excel spreadsheets using the handy IronXL API Reference Documentation.

IronXL API Reference Documentation

Frequently Asked Questions

What is the one-line solution provided by IronXL for reading CSV files in C#?

IronXL provides the `LoadCSV` method, which allows you to read a CSV file in C# with a simple command.

How can I convert a CSV file to Excel using IronXL?

You can convert a CSV file to Excel by loading the CSV using the `LoadCSV` method and then saving it as an Excel file with the `SaveAs` method.

Can I use custom delimiters when reading CSV files with IronXL?

Yes, IronXL supports custom delimiters, allowing you to specify different characters such as semicolons, tabs, or pipes in the `LoadCSV` method.

Is IronXL capable of handling large CSV files efficiently?

IronXL is optimized for performance and can handle large CSV files efficiently, making it suitable for processing substantial datasets.

What are the different file formats to which I can export CSV data using IronXL?

Using IronXL, you can export CSV data to multiple formats, including Excel (XLSX), JSON, XML, and HTML.

How do I read CSV files in an ASP.NET MVC web application with IronXL?

In an ASP.NET MVC web application, you can process uploaded CSV files using the `LoadCSV` method in IronXL, which can then be converted to a DataTable for display.

Does IronXL provide advanced options for handling complex CSV data?

Yes, IronXL offers advanced features such as working with formulas, handling special characters, and setting cell data formats when processing complex CSV files.

Can I install IronXL via NuGet in Visual Studio?

Yes, you can install IronXL using the NuGet Package Manager in Visual Studio by searching for `IronXL.Excel` and adding it to your project.

What namespace do I need to import to use IronXL functionalities in my C# project?

To access IronXL functionalities, you need to import the `IronXL` namespace into your C# project.

What types of projects can benefit from using IronXL for CSV file processing?

IronXL is beneficial for .NET applications, including MVC, ASP, and .NET Core projects, where seamless CSV reading and conversion are required.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Ready to Get Started?

Nuget Downloads 2,237,574Version:2026.9just released

Get your FREE

30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
bullet_testTest in production
without watermarks
bullet_calendar30 days fully
functional product
bullet_support24/5 technical
support during trial
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronXL.Excel
nuget.org/packages/IronXL.Excel/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronXL"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

  1. Download and unzip IronXL to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronXL.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required