How to Attach an HTML Tag to the HEAD of an HTML Doc in C#

The HEAD section of an HTML document is nestled between an HTML tag and the BODY tag, and contains metadata such as title, scripts, and styles. If you need an automatic approach for appending an HTML tag to the HEAD section and ensuring your HTML document has all the required elements, the following API can be used in C# to do just that.

First, we will run this command to install the API Client:

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

With the installation out of the way, we can call the function with the following code:

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 EditHtmlHtmlAppendHeaderTagExample
public void main()
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");
var apiInstance = new EditHtmlApi();
var htmlTag = htmlTag_example; // string | The HTML tag to append.
var inputFile = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Optional: Input file to perform the operation on. (optional)
var inputFileUrl = inputFileUrl_example; // string | Optional: URL of a file to operate on as input. (optional)
// Append an HTML tag to the HEAD section of an HTML Document
byte[] result = apiInstance.EditHtmlHtmlAppendHeaderTag(htmlTag, inputFile, inputFileUrl);
catch (Exception e)
Debug.Print("Exception when calling EditHtmlApi.EditHtmlHtmlAppendHeaderTag: " + e.Message );

And we’re done! To retrieve your API key, head to the Cloudmersive website to register for a free account; this will provide 800 calls/month across our library of APIs.

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