C#.NET Import/Export CSV Library

Importing and exporting are some of the basic operations used in any sort of development. So, for this purpose, I have created a very simple C#.NET library for importing/exporting the CSV data using Datatable as a primary data structure. You can use this library into your C#.NET project that supports Datatable data structure. This library imports CSV files with or without header and with any number of columns into C#.NET Datatable structure. The import function will automatically detect the number of columns of the CSV file. The export method will export your data from C#.NET Datatable data structure to .csv format file.
 
Today, I shall be demonstrating the basic use of my .NET library for importing/exporting CSV data using Datatable as a primary data structure.
 
C#.Net Import/Export CSV Library
 
Prerequisites
 
Following are some prerequisites before you proceed any further in this tutorial:
  1. Install CSVLibraryAK NuGet library.
  2. Knowledge of C# Programming.
You can install my library via Nuget packages or you can download pre-compile DLL library. The example code is being developed in Microsoft Visual Studio 2017 Professional.
 
 
Let's begin now.
 
Step 1
 
Create a new Console Application project and name it "CSVImportExport". 
 
Step 2
 
 Install 'CSVLibraryAK' Nuget library into your project.
 
Step 3
 
Create "CSVImportExport.cs" file and replace following code in it i.e.
  1. ...  
  2.     using CSVLibraryAK;  
  3. ...  
  4.     public static void Main(string[] args)  
  5.         {  
  6.             // Initialization.  
  7.             bool hasHeader = true;  
  8.             string importFilePath = "E:\\import.csv";  
  9.             string exportFilePath = "E:\\export.csv";  
  10.   
  11.             // Impot CSV file.  
  12.             DataTable data = CSVLibraryAK.Import(importFilePath, hasHeader);  
  13.   
  14.             // Export CSV file.  
  15.             CSVLibraryAK.Export(exportFilePath, data);  
  16.         }  
  17. ... 
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 Nuget library.
 
Step 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 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.


Similar Articles