Merge CSV

How to merge CSV files in C#

GroupDocs.Merger allows developers to merge CSV files when it’s needed to organize multiple CSV files into single document or send fewer attachments etc. And you can do this without¬†any third-party software or manual work involved. With GroupDocs.Merger it is possible to combine CSV documents of any size and structure - all text, images, tables, graphs, forms and other content will be preserved.

The following example demonstrates how to merge CSV files with several lines of C# code:

  • Create an instance of Merger class and pass source CSV file path as a constructor parameter. You may specify absolute or relative file path as per your requirements.
  • Add another CSV file to merge with Join method. Repeat this step for other CSV documents you want to merge.
  • Call Merger class Save method and specify the filename for the merged CSV file as parameter.
// Load the source CSV file
using (Merger merger = new Merger(@"c:\sample1.csv"))
{
    // Add another CSV file to merge
    merger.Join(@"c:\sample2.csv");
    // Merge CSV files ans save result
    merger.Save(@"c:\merged.csv");
}

About CSV File Format

Files with CSV (Comma Separated Values) extension represent plain text files that contain records of data with comma separated values. Each line in a CSV file is a new record from the set of records contained in the file. Such files are generated when data transfer is intended from one storage system to another. Since all applications can recognize records separated by comma, import of such data files to database is done very conveniently.

Code Examples

Please find more use-cases and complete C# sources of our backend and frontend examples and try them for free!

Merge CSV Live Demo

GroupDocs.Merger for .NET provides an online CSV Merger App, which allows you to try it for free and check its quality and accuracy.

“Merge CSV”