How To Run IronWord with .NET on Azure

IronWord is a powerful .NET library for creating, editing, and reading Word documents programmatically. It works seamlessly on various Azure services including Azure App Services, Azure Functions, and Azure Container Instances.

Installing IronWord

Begin by installing the IronWord NuGet package from the official NuGet repository:

Install-Package IronWord

Hosting Considerations for Azure

Choosing the Right Azure Service Tier

IronWord performs best on Azure service plans that provide consistent compute availability. For most small to medium use cases, the Basic (B1) App Service Plan is sufficient. If your application processes a high volume of Word documents or performs complex formatting tasks, consider upgrading to Standard (S1) or higher tiers to avoid performance bottlenecks.

Supported .NET Runtimes and Compatibility

IronWord works out of the box with the following frameworks commonly used in Azure-hosted solutions:

  • .NET 6+ (LTS recommended)
  • .NET Core 3.1
  • .NET Standard 2.1

This gives you flexibility to deploy IronWord across various Azure services like App Services, Azure Functions, and Docker containers without worrying about compatibility.

Deploying in Docker on Azure

Containerized Deployment with IronWord

If you're looking for maximum control over your runtime environment, consider deploying IronWord inside a Docker container on Azure Container Instances (ACI) or Azure Kubernetes Service (AKS). This allows you to:

  • Pre-load templates or static resources
  • Configure document processing settings
  • Fine-tune performance at the OS level

To get started, use a base image such as mcr.microsoft.com/dotnet/aspnet:6.0 or 7.0 and add IronWord via NuGet or manual DLL inclusion.

Serverless with Azure Functions

Using IronWord in Azure Functions

IronWord is fully compatible with Azure Functions v4 running on .NET 6 or higher. This enables lightweight, event-driven document generation—perfect for scenarios like:

  • On-demand report creation via HTTP
  • Generating Word documents from form submissions
  • Converting structured data into .docx format

Azure Function Example: Generate Word Document on Request

Below is a real-world example of an Azure Function that creates and returns a Word document in response to an HTTP request:

using System.Net;
using System.Net.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using System.Net.Http.Headers;
using IronWord;
using IronWord.Models;
using System.IO;
using System.Threading.Tasks;

public static class WordFunction
{
    [FunctionName("GenerateWordDoc")]
    public static HttpResponseMessage Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
        ILogger log)
    {
        log.LogInformation("Processing request to generate Word document...");

        // Set your IronWord license key
        IronWord.License.LicenseKey = "YOUR-LICENSE-KEY";

        // Create and populate Word document
        var doc = new WordDocument();
        Paragraph para1 = new Paragraph(new TextContent("This Word document was generated by IronWord in an Azure Function."));
        Paragraph para2 = new Paragraph(new TextContent($"Timestamp: {System.DateTime.UtcNow}"));
        doc.AddParagraph(para1);
        doc.AddParagraph(para2);

        // Save to temporary file
        string tempPath = Path.GetTempFileName().Replace(".tmp", ".docx");
        doc.SaveAs(tempPath);

        // Read the file bytes
        byte[] fileBytes = File.ReadAllBytes(tempPath);

        // Optionally delete the temp file
        File.Delete(tempPath);

        // Build the response with the document as an attachment
        var response = new HttpResponseMessage(HttpStatusCode.OK)
        {
            Content = new ByteArrayContent(fileBytes)
        };
        response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
        {
            FileName = $"IronWord_{System.DateTime.UtcNow:yyyyMMdd_HHmmss}.docx"
        };
        response.Content.Headers.ContentType = new MediaTypeHeaderValue(
            "application/vnd.openxmlformats-officedocument.wordprocessingml.document");

        return response;
    }
}
using System.Net;
using System.Net.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using System.Net.Http.Headers;
using IronWord;
using IronWord.Models;
using System.IO;
using System.Threading.Tasks;

public static class WordFunction
{
    [FunctionName("GenerateWordDoc")]
    public static HttpResponseMessage Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
        ILogger log)
    {
        log.LogInformation("Processing request to generate Word document...");

        // Set your IronWord license key
        IronWord.License.LicenseKey = "YOUR-LICENSE-KEY";

        // Create and populate Word document
        var doc = new WordDocument();
        Paragraph para1 = new Paragraph(new TextContent("This Word document was generated by IronWord in an Azure Function."));
        Paragraph para2 = new Paragraph(new TextContent($"Timestamp: {System.DateTime.UtcNow}"));
        doc.AddParagraph(para1);
        doc.AddParagraph(para2);

        // Save to temporary file
        string tempPath = Path.GetTempFileName().Replace(".tmp", ".docx");
        doc.SaveAs(tempPath);

        // Read the file bytes
        byte[] fileBytes = File.ReadAllBytes(tempPath);

        // Optionally delete the temp file
        File.Delete(tempPath);

        // Build the response with the document as an attachment
        var response = new HttpResponseMessage(HttpStatusCode.OK)
        {
            Content = new ByteArrayContent(fileBytes)
        };
        response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
        {
            FileName = $"IronWord_{System.DateTime.UtcNow:yyyyMMdd_HHmmss}.docx"
        };
        response.Content.Headers.ContentType = new MediaTypeHeaderValue(
            "application/vnd.openxmlformats-officedocument.wordprocessingml.document");

        return response;
    }
}
Imports System
Imports System.Net
Imports System.Net.Http
Imports Microsoft.AspNetCore.Http
Imports Microsoft.Azure.WebJobs
Imports Microsoft.Azure.WebJobs.Extensions.Http
Imports Microsoft.Extensions.Logging
Imports System.Net.Http.Headers
Imports IronWord
Imports IronWord.Models
Imports System.IO
Imports System.Threading.Tasks

Public Module WordFunction
	<FunctionName("GenerateWordDoc")>
	Public Function Run(<HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route := Nothing)> ByVal req As HttpRequest, ByVal log As ILogger) As HttpResponseMessage
		log.LogInformation("Processing request to generate Word document...")

		' Set your IronWord license key
		IronWord.License.LicenseKey = "YOUR-LICENSE-KEY"

		' Create and populate Word document
		Dim doc = New WordDocument()
		Dim para1 As New Paragraph(New TextContent("This Word document was generated by IronWord in an Azure Function."))
		Dim para2 As New Paragraph(New TextContent($"Timestamp: {DateTime.UtcNow}"))
		doc.AddParagraph(para1)
		doc.AddParagraph(para2)

		' Save to temporary file
		Dim tempPath As String = Path.GetTempFileName().Replace(".tmp", ".docx")
		doc.SaveAs(tempPath)

		' Read the file bytes
		Dim fileBytes() As Byte = File.ReadAllBytes(tempPath)

		' Optionally delete the temp file
		File.Delete(tempPath)

		' Build the response with the document as an attachment
		Dim response = New HttpResponseMessage(HttpStatusCode.OK) With {.Content = New ByteArrayContent(fileBytes)}
		response.Content.Headers.ContentDisposition = New ContentDispositionHeaderValue("attachment") With {.FileName = $"IronWord_{DateTime.UtcNow:yyyyMMdd_HHmmss}.docx"}
		response.Content.Headers.ContentType = New MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.wordprocessingml.document")

		Return response
	End Function
End Module
$vbLabelText   $csharpLabel

Code Explanation:

  1. We define an Azure Function with the name "GenerateWordDoc".
  2. The function is triggered by an HTTP GET or POST request and logs a message when it begins processing.
  3. We specify the license key for IronWord by setting IronWord.License.LicenseKey (replace "YOUR-LICENSE-KEY" with your actual key).
  4. A new WordDocument is created using IronWord's API.
  5. Two paragraphs are added to the document — one with static text and another showing the current UTC timestamp.
  6. The document is saved to a temporary .docx file on the server using doc.SaveAs(tempPath).
  7. The saved file is read into a byte array using File.ReadAllBytes, preparing it for download.
  8. The temporary file is deleted immediately after reading to keep the system clean.
  9. An HttpResponseMessage is built, containing the document's byte content as a downloadable attachment.
  10. The Content-Disposition header sets the download filename using the current date and time.
  11. The Content-Type header is set to "application/vnd.openxmlformats-officedocument.wordprocessingml.document" to indicate a Word file format.
Kye Stuart
Technical Writer

Kye Stuart merges coding passion and writing skill at Iron Software. Educated at Yoobee College in software deployment, they now transform complex tech concepts into clear educational content. Kye values lifelong learning and embraces new tech challenges.

Outside work, they enjoy PC gaming, streaming on Twitch, and outdoor activities like gardening and walking their dog, Jaiya. Kye’s straightforward approach makes them key to Iron Software’s mission to demystify technology for developers globally.

Talk to an Expert Five Star Trust Score Rating

Ready to Get Started?

Nuget Passed