How to Merge Multiple HTML Files Together using C# .NET Framework

Cloudmersive
2 min readJan 18, 2024

--

Separately storing or sharing a bunch of related HTML files creates unnecessary clutter. With just a few lines of code, we can easily merge our HTML documents together and save quite a bit of hassle.

In fact, we can use the complementary code provided below to take advantage of an API that’ll merge our HTML files for us. We can merge 10 or more HTML files at once, and we can use this service up to 800 times per month for free with a free-tier API key.

To structure our API call, let’s start by installing the SDK. We can do that in NuGet by running the following command in our Package Manager console:

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

Next, we can call the function using the below code, and we can enter our API key to authorize our requests:

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 MergeDocumentHtmlMultiExample
{
public void main()
{
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");

var apiInstance = new MergeDocumentApi();
var inputFile1 = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | First input file to perform the operation on.
var inputFile2 = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Second input file to perform the operation on.
var inputFile3 = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Third input file to perform the operation on. (optional)
var inputFile4 = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Fourth input file to perform the operation on. (optional)
var inputFile5 = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Fifth input file to perform the operation on. (optional)
var inputFile6 = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Sixth input file to perform the operation on. (optional)
var inputFile7 = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Seventh input file to perform the operation on. (optional)
var inputFile8 = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Eighth input file to perform the operation on. (optional)
var inputFile9 = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Ninth input file to perform the operation on. (optional)
var inputFile10 = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Tenth input file to perform the operation on. (optional)

try
{
// Merge Multple HTML (HTM) Files Together
byte[] result = apiInstance.MergeDocumentHtmlMulti(inputFile1, inputFile2, inputFile3, inputFile4, inputFile5, inputFile6, inputFile7, inputFile8, inputFile9, inputFile10);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling MergeDocumentApi.MergeDocumentHtmlMulti: " + e.Message );
}
}
}
}

Just like that, we’ve incorporated a free, low-code service for merging our HTML files.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet