Recursive AI

Convert DOC to DOCX in C#

OneDocument is a free, open-source Word, Excel and PowerPoint document library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

Read an older .doc file and write a standard, editable .docx file without installing Office.

Terminal
dotnet add package RecursiveAI.OneDocument.Documents

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using RecursiveAI.OneDocument.Documents;
 
using var doc = Document.Open("basic.doc");
doc.SaveAs("converted.docx");
Console.WriteLine("Wrote converted.docx");
Text
Wrote converted.docx

Unzip the example, then dotnet run.

basic.doc is in the zip. It is a generated sample from the public repository with headings, formatted text, tab stops, a link and a page break; its text appears in the output below.

The full program

The download’s Program.cs uses the supplied samples:

C#
using RecursiveAI.OneDocument.Documents;
 
using Document doc = Document.Open("basic.doc");
doc.SaveAs("converted.docx");
Console.WriteLine("Wrote converted.docx");
Console.WriteLine($"Import losses: {doc.ImportLoss!.Items.Count}");
foreach (Paragraph paragraph in doc.Paragraphs)
    Console.WriteLine(paragraph.Text);

dotnet run prints:

Text
Wrote converted.docx
Import losses: 0
Quarterly report
Plain, bold, italic, underlined and large red.
Centered paragraph
Indented with spacing
Item	42
Visit the site.
Before the break
After the break

Features without a mapped counterpart appear in ImportLoss; review that report before replacing the original.

Variations

Read the import loss report

C#
using RecursiveAI.OneDocument.Documents;
 
using var doc = Document.Open("basic.doc");
foreach (var loss in doc.ImportLoss!.Items)
    Console.WriteLine(loss);
Console.WriteLine($"Import losses: {doc.ImportLoss.Items.Count}");

Output:

Text
Import losses: 0

The short answer

Open the .doc file with Document.Open and save it to a new .docx path. OneDocument reads the older .doc file and writes a standard .docx file; Office does not need to be installed. Changing the filename extension alone does not perform this conversion.

This is a managed .NET conversion, not Word automation. The Documents package includes the reader and the DOCX writer. The binary Word documentation describes the supported input versions and the features carried into the document model.

How do I convert DOC to DOCX in C#?

Use the snippet at the top for a single file. Keep the source path distinct from the output so you have the original available when reviewing the result. The full program also prints the imported paragraphs and the number of reported import losses. That gives a useful starting point for a conversion workflow, but it is not a visual comparison of the two documents.

The reader handles Word 97 through Word 2013 binary documents, Word 6.0 and Word 95 files, and incrementally saved files. DOC is an input format here: the library does not write the binary Word format. The output is a standard .docx file that can be edited in code or opened in Word.

The conversion carries text and supported formatting, tables, lists, fields, bookmarks, notes, comments, headers, footers and sections. The scope is feature-specific, so a successful save does not mean every binary feature has a direct DOCX counterpart. Review Document.ImportLoss, as shown in the variation, for the actual source you are converting.

Can I convert DOC to DOCX for free?

Yes. The sample uses the free, open-source Documents package from NuGet and a generated input included under the repository’s license. No Word installation is needed to run it. Replace basic.doc with your own path after trying the supplied example, and retain both files until you have checked the converted document.

Some conversions need human review even when the text is intact. Text boxes are appended after the body as paragraphs rather than keeping their position and frame. Header text boxes and non-picture drawing shapes are dropped. Form fields retain ordinary field content but lose check-box state and drop-down lists. Unmapped property modifiers and other supported loss categories are listed in the import report.

Word 6/95 formatting has its own loss category. A VBA storage in a DOC source is also reported as an import loss. If your goal is specifically to remove a macro project while preserving a binary file, that is a different operation from converting it to DOCX. Use the macro-removal recipe for that task. For conversion, review the loss report and inspect the layout in the editor that will receive the document, especially for a file with floating content or complex forms.

All onedocument recipes