How to merge two text TXT files together in C# .NET Framework

Merging TXT files is going to be a snap after you follow this ultra-quick tutorial.

We are going to start by installing our API client via Package Manager; simply run this command in your console.

Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 2.2.0

Next step, invoke the function MergeDocumentTxt, and drop in your two files to be merged.

using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;namespace Example{public class MergeDocumentTxtExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new MergeDocumentApi();var inputFile1 = new System.IO.Stream(); // System.IO.Stream | First input file to perform the operation on.var inputFile2 = new System.IO.Stream(); // System.IO.Stream | Second input file to perform the operation on (more than 2 can be supplied).try{// Merge Two Text (TXT) Files TogetherObject result = apiInstance.MergeDocumentTxt(inputFile1, inputFile2);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling MergeDocumentApi.MergeDocumentTxt: " + e.Message );}}}}

Easy. The API will return us the merged TXT file. You may like some of our other functions, which encompass a very wide range of useful features; everything from format conversion to document editing.

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store