Convert DOC to DOCX in C#

DocToDocxConverter reads a Word 97-2003 .doc file and writes a modern .docx package. Text, tables and character formatting such as bold come through intact.

using DocToolkit;

byte[] doc = File.ReadAllBytes("input.doc");
byte[] docx = DocToDocxConverter.Convert(doc);
File.WriteAllBytes("output.docx", docx);

What it needs

  • No browser, headless or otherwise.
  • No Office install, and no LibreOffice.
  • No native files: managed code only.
  • No network at runtime, unless you ask for it.

Good to know

  • Synchronous: DocToDocxConverter.Convert takes the .doc as a byte[] and returns the .docx as a byte[].
  • It refuses a .doc holding pictures, drawings or form fields that a .docx cannot carry, rather than drop them quietly. Set LegacyDocOptions.AllowContentLoss to accept the loss on purpose.
  • ConvertWithReport returns the same bytes and a list of what the import could not carry across.
  • Import only: it reads .doc and never writes one.

Install

dotnet add package Ank.DocToolkit

NuGetDocumentationGitHub