Header Ads

C#.Net Core: Import/Export CSV Library

I have previously created a simple C#.NET nuget library for importing/exporting CSV data using Datatable as a primary data structure. Now, I have migrated this library exclusively for C#.NET Core projects into a separate nuget library i.e. CSVLibraryAK.Core.

Today, I shall be demonstrating the basic use of my .NET Core Nuget library for importing/exporting CSV data using Datatable as a primary data structure.


Prerequisites:

Following are some prerequisites before you proceed any further in this tutorial:
  1. Install CSVLibraryAK.Core NuGet library.
  2. Knowledge of C# Programming.
You can install the library via Nuget packages. The example code is being developed in Microsoft Visual Studio 2019 Professional.

Download Now! Nuget Installation

Let's begin now.

1) Create a new Console Application project and name it "CSVImportExport". 

2) Install 'CSVLibraryAK.Core' Nuget library into your project.

3) Create "CSVImportExport.cs" file and in the main method add following lines of code i.e.

...
    using CSVLibraryAK.Core;
...
    // Impot CSV file.
    DataTable data = CSVLibraryAK.Import(importFilePath, hasHeader);

    // Export CSV file.
    CSVLibraryAK.Export(exportFilePath, data);
...

In the above code, I am simply importing my target CSV file into DataTable data structure and then export my data from DataTable data structure to my destination CSV file using my CSVLibraryAK.Core Nuget library.

4) Now, execute the project and you will be able to see the export file in your target destination folder.

Conclusion

In this article, you will learn to use my .NET Core Nuget library for importing/exporting CSV data using Datatable as a primary data structure. You will also learn to import/export your target CSV file data.

No comments