How to Import/Export CSV File Data in ASP.NET Core MVC Web App
I have previously created a simple C#.NET nuget library for importing/exporting CSV data from file 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. You can also utilize this library into your any .NET Core web project as well.
Today, I shall be demonstrating integration of CSVLibraryAK.Core a C#.NET Core library with ASP.NET Core MVC web platform.
1) Create a new MVC web project and name it "MVCImportExportCSV.Core".
Today, I shall be demonstrating integration of CSVLibraryAK.Core a C#.NET Core library with ASP.NET Core MVC web platform.
Prerequisites:
Following are some prerequisites before you proceed any further in this tutorial:- Install CSVLibraryAK.Core NuGet library.
- Knowledge of ASP.NET Core MVC.
- Knowledge of HTML.
- Knowledge of JavaScript.
- Knowledge of Bootstrap.
- Knowledge of Jquery.
- Knowledge of C# Programming.
Download Now!
Let's begin now.1) Create a new MVC web project and name it "MVCImportExportCSV.Core".
2) Open "Tools\Nuget Package Manage\Manage Nuget Packages for Solution...".
3) Install CSVLibraryAK.Core Nuget Package.
4) Create a new "Controllers\HomeController.cs" file and add this library into the using directives as shown below i.e.
... namespace MVCImportExportCSV.Controllers { ... using CSVLibraryAK.Core; ... } ...
In the above code, I have simply included the CSVlibraryAK.Core library into my using directive.
5) Now, create a simple view with action method in the controller and view file to enable user to upload his/her CSV file to your web server and use this library's import method to import and display the CSV data into display view via Datatables data structure and then use this library's export method to export and save that uploaded CSV data from the display view grid to a CSV file on the web server with the help of following lines of code i.e.
... // Impot CSV file. model.Data = CSVLibraryAK.Import(importFilePath, model.HasHeader); // Export CSV file. CSVLibraryAK.Export(exportFilePath, model.Data); ...
In the above code, I am using the library's import and export methods to import and export the CSV file data on to my asp.net core mvc web server.
6) Now, execute the project and you
will be able to see the following in
action i.e.
can i download this project from somewhere ?
ReplyDeleteLink in provided
Deleteit is very informative artical
ReplyDeleteIs this free??
ReplyDelete