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