Header Disappears After SaveAs in IronWord

When you populate a DOCX template with IronWord and write the result with SaveAs(), the template's header can vanish from the generated file. The placeholders merge correctly, but the header present in the source document does not survive the save.

Header (e.g. "City Attorney Cover Sheet") is visible in the original DOCX
but missing in the generated file after calling SaveAs().

Word template with unreplaced placeholders and no header

The header is preserved when you write the document with Save() rather than SaveAs(). This was confirmed on IronWord 2026.2.1, a .NET 8 console application running on Windows 11 Enterprise x64 (24H2).

Solution

1. Load the Template

Open the source DOCX with WordDocument.

using IronWord;
using System.Collections.Generic;

var templatePath = @"C:\Templates\CityAttorneyCoverSheetTemplate.docx";
var outputPath   = @"C:\Output\merged.docx";

var doc = new WordDocument(templatePath);
using IronWord;
using System.Collections.Generic;

var templatePath = @"C:\Templates\CityAttorneyCoverSheetTemplate.docx";
var outputPath   = @"C:\Output\merged.docx";

var doc = new WordDocument(templatePath);
Imports IronWord
Imports System.Collections.Generic

Dim templatePath As String = "C:\Templates\CityAttorneyCoverSheetTemplate.docx"
Dim outputPath As String = "C:\Output\merged.docx"

Dim doc As New WordDocument(templatePath)
$vbLabelText   $csharpLabel

2. Replace the Placeholders

Merge your values through doc.Texts, which is the recommended approach for template replacement.

var replacements = new Dictionary<string, string>
{
    ["{CaseNumber}"] = "2026-CR-12345",
    ["{DefendantName}"] = "John Doe",
    ["{DefendantAge}"] = "34",
    ["{DefendantAttorney}"] = "Jane Smith",
};

foreach (var kv in replacements)
{
    doc.Texts.ForEach(t => t.Replace(kv.Key, kv.Value));
}
var replacements = new Dictionary<string, string>
{
    ["{CaseNumber}"] = "2026-CR-12345",
    ["{DefendantName}"] = "John Doe",
    ["{DefendantAge}"] = "34",
    ["{DefendantAttorney}"] = "Jane Smith",
};

foreach (var kv in replacements)
{
    doc.Texts.ForEach(t => t.Replace(kv.Key, kv.Value));
}
Imports System.Collections.Generic

Dim replacements As New Dictionary(Of String, String) From {
    {"{CaseNumber}", "2026-CR-12345"},
    {"{DefendantName}", "John Doe"},
    {"{DefendantAge}", "34"},
    {"{DefendantAttorney}", "Jane Smith"}
}

For Each kv In replacements
    doc.Texts.ForEach(Sub(t) t.Replace(kv.Key, kv.Value))
Next
$vbLabelText   $csharpLabel

Iterating each entry over doc.Texts swaps every placeholder token for its merge value across the document body.

3. Save With Save(), Not SaveAs()

Write the output with doc.Save(outputPath). This keeps the header intact, where doc.SaveAs(outputPath) may drop it.

doc.Save(outputPath);
doc.Save(outputPath);
doc.Save(outputPath)
$vbLabelText   $csharpLabel

Merged Word document with header preserved and placeholders filled

Notes

  • If your workflow requires SaveAs(): verify on the latest IronWord version whether the header survives in your environment.
  • If the issue reappears: pin to a previously working version as a short-term mitigation while the behavior is investigated.

Please notePlaceholders are still found and replaced during traversal even when the header is lost, so a successful merge alone is not confirmation the header was kept. Open the output and check.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More
Ready to Get Started?
Nuget Downloads 47,210 | Version: 2026.7 just released
Still Scrolling Icon

Still Scrolling?

Want proof fast? PM > Install-Package IronWord
run a sample watch your data become a Word doc.