Syncfusion AI Assistant

How can I help you?

Word File Formats in Essential® DocIO

7 Apr 202622 minutes to read

Microsoft Word supports multiple file formats that differ in structure, capabilities, and intended usage. Essential® DocIO provides read and write support for modern XML-based formats (DOCX, DOTX, DOCM, DOTM), Word Processing XML formats (WordML), and binary Word documents (DOC, DOT), as well as HTML, RTF, and Markdown formats.

This documentation categorizes the major Word file formats into:

  1. Word Open XML formats (2007 & later)
  2. Word Processing XML (.xml)
  3. Word Binary (97-2003) format (classic)

Word Open XML formats (2007 & later)

Word Open XML formats (DOCX, DOTX, DOCM, DOTM) are ZIP-compressed file packages that contain multiple XML parts representing document content, styles, settings, and relationships. These documents store their content using WordprocessingML, an XML-based markup language defined by the Office Open XML standard.

Essential® DocIO supports Word Open XML documents compatible with:

  • Microsoft Word 2007
  • Microsoft Word 2010
  • Microsoft Word 2013
  • Microsoft Word 2016
  • Microsoft Word 2019

Word Document (DOCX)

DOCX is the default XML-based file format introduced in Microsoft Word 2007 and is commonly used for general document processing scenarios.

Click here to learn how to create a new Word document with a few lines of code.

Word Template (DOTX)

DOTX is a Word document template. Templates are useful when you regularly produce similar types of documents, as they let you start from a ready-made structure instead of building the document from scratch each time.

The following code example illustrates how to create the Word document template with a few lines of code.

NOTE

Refer to the appropriate tabs in the code snippets section: C# [Cross-platform] for ASP.NET Core, Blazor, Xamarin, UWP, .NET MAUI, and WinUI; C# [Windows-specific] for WinForms and WPF; VB.NET [Windows-specific] for VB.NET applications.

//Creates a new instance of WordDocument (Empty Word Document)
using (WordDocument document = new WordDocument())
{
    //Adds a section and a paragraph to the document
    document.EnsureMinimal();
    //Appends text to the last paragraph of the document
    document.LastParagraph.AppendText("Hello World");
    //Saves the Word document to MemoryStream
    MemoryStream stream = new MemoryStream();
    document.Save(stream, FormatType.Dotx);
    //Closes the Word document
    document.Close();
}
//Creates an instance of WordDocument Instance (Empty Word Document)
WordDocument document = new WordDocument();
//Adds a section and a paragraph to the document
document.EnsureMinimal();
//Appends text to the last paragraph of the document
document.LastParagraph.AppendText("Hello World");
//Saves and closes the Word document
document.Save("Sample.dotx");
document.Close();
'Creates an instance of WordDocument Instance (Empty Word Document)
Dim document As New WordDocument()
'Adds a section and a paragraph to the document
document.EnsureMinimal()
'Appends text to the last paragraph of the document
document.LastParagraph.AppendText("Hello World")
'Saves and closes the Word document
document.Save("Sample.dotx")
document.Close()

You can download a complete working sample from GitHub.

Macros (DOCM, DOTM)

DOCM and DOTM are macro-enabled Word Open XML formats. DOCM represents a macro-enabled Word document, while DOTM represents a macro-enabled Word template. These formats are structurally similar to DOCX and DOTX, but additionally contain embedded VBA macro code.

Essential® DocIO allows macro-enabled Word documents to be loaded and saved with macros preserved. In addition, macros can be removed explicitly by using the RemoveMacros method when required.

For further information, click here.

Word Processing XML (.xml)

Word Processing XML (WordML) is a single‑file XML format introduced in Microsoft Word 2003 to represent Word document content in XML.

The Essential® DocIO supports converting the Word document into Word Processing XML document and vice versa.

NOTE

  1. Importing and exporting Word Processing 2007 XML documents is supported.
  2. Exporting Word Processing 2003 XML documents is not supported. However, you can import Word Processing 2003 XML documents and export them to other supported file formats.
  3. Custom XML elements present in Word Processing 2003 XML documents are removed automatically during import, similar to the behavior of recent versions of Microsoft Word. Custom XML elements are a deprecated feature in newer Word versions.

Word to WordML

The following code example illustrates how to convert a Word document into a Word Processing XML document.

FileStream fileStreamPath = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
//Opens an existing document from file system through constructor of WordDocument class
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
{
    //Saves the Word document to MemoryStream
    MemoryStream stream = new MemoryStream();
    document.Save(stream, FormatType.WordML);
    //Closes the Word document
    document.Close();
}
//Loads an existing Word document
WordDocument document = new WordDocument("Template.docx");
//Saves the document as Word Processing XML document
document.Save("WordToWordML.xml", FormatType.WordML);
//Closes the document
document.Close();
'Loads an existing Word document 
Dim document As New WordDocument("Template.docx")
'Saves the document as Word Processing XML document
document.Save("WordToWordML.xml", FormatType.WordML)
'Closes the document
document.Close()

You can download a complete working sample from GitHub.

WordML to Word

The following code example illustrates how to convert a Word Processing XML document into a Word document.

FileStream fileStreamPath = new FileStream("Template.xml", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
//Opens an existing document from file system through constructor of WordDocument class
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.WordML))
{
    //Saves the Word document to MemoryStream
    MemoryStream stream = new MemoryStream();
    document.Save(stream, FormatType.Docx);
    //Closes the Word document
    document.Close();
}
//Loads an existing Word document 
WordDocument document = new WordDocument("Template.xml");
//Saves the Word Processing XML document as docx
document.Save("WordMLToWord.docx", FormatType.Docx);
//Closes the document
document.Close();
'Loads an existing Word document 
Dim document As New WordDocument("Template.xml")
'Saves the Word Processing XML document as docx 
document.Save("WordMLToWord.docx", FormatType.Docx)
'Closes the document
document.Close()

You can download a complete working sample from GitHub.

Supported elements in Word Processing XML conversion

Word Processing XML conversion supports all common Word document elements such as paragraphs, text, tables, images, and other standard formatting elements. The following table highlights the support status of specific elements that may have limitations or behavior differences during conversion.

Element Word to WordML Word Processing 2007 XML document to Word Word Processing 2007 XML document to WordML Word Processing 2003 XML document to Word / WordML
Custom Shapes

Yes

Yes

Yes

Yes

Embedded fonts

Yes

Yes

Yes

No

Equation

Yes

Yes

Yes

No

SmartArt

No

Yes

No

No

WordArt

Yes

Yes

Yes

No

Form Fields

Yes

Yes

Yes

No

Ole Object

Yes

Yes

Yes

No

Word Binary (97-2003) format

DOC is the binary file format used in Word 97–Word 2003 and is one of the classic file formats for Word processing documents. It is a proprietary binary format developed by Microsoft that is supported across Microsoft Word versions and maintained mainly for backward compatibility.

The Essential® DocIO library supports importing and exporting DOC format documents.

The following code example illustrates how to create a binary format document with a few lines of code.

//Creates a new instance of WordDocument (Empty Word Document)
using (WordDocument document = new WordDocument())
{
    //Adds a section and a paragraph to the document
    document.EnsureMinimal();
    //Appends text to the last paragraph of the document
    document.LastParagraph.AppendText("Hello World");
    MemoryStream stream = new MemoryStream();
    //Saves and closes the Word document to MemoryStream
    document.Save(stream, FormatType.Doc);
    document.Close();
}
//Creates an instance of WordDocument Instance (Empty Word Document)
WordDocument document = new WordDocument();
//Adds a section and a paragraph to the document
document.EnsureMinimal();
//Appends text to the last paragraph of the document
document.LastParagraph.AppendText("Hello World");
//Saves and closes the Word document
document.Save("BinaryDocument.doc");
document.Close();
'Creates an instance of WordDocument Instance (Empty Word Document)
Dim document As New WordDocument()
'Adds a section and a paragraph to the document
document.EnsureMinimal()
'Appends text to the last paragraph of the document
document.LastParagraph.AppendText("Hello World")
'Saves and closes the Word document
document.Save("BinaryDocument.doc ")
document.Close()

You can download a complete working sample from GitHub.

DOC to DOCX

The following code example illustrates how to convert a DOC file into the DOCX file format using DocIO.

FileStream fileStreamPath = new FileStream("Template.doc", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
//Opens an existing document from file system through constructor of WordDocument class
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Doc))
{
    //Saves the Word document to MemoryStream
    MemoryStream stream = new MemoryStream();
    document.Save(stream, FormatType.Docx);
    //Closes the Word document
    document.Close();
}
//Loads an existing document
WordDocument document = new WordDocument("Template.doc", FormatType.Doc);
//Saves the binary document(.doc) as Word Document(.docx) file
document.Save("DocToWord.docx", FormatType.Docx);
//Closes the document
document.Close();
'Loads an existing document
Dim document As New WordDocument("Template.doc", FormatType.Doc)
'Saves the binary document(.doc) as Word Document(.docx) file
document.Save("DocToWord.docx", FormatType.Docx)
'Closes the document
document.Close()

You can download a complete working sample from GitHub.

DOCX to DOC

The following code example illustrates how to convert a DOCX file into the DOC file format using DocIO.

FileStream fileStreamPath = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
//Opens an existing document from file system through constructor of WordDocument class
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
{
    //Saves the Word document to MemoryStream
    MemoryStream stream = new MemoryStream();
    document.Save(stream, FormatType.Doc);
    //Closes the Word document
    document.Close();
}
//Loads an existing document
WordDocument document = new WordDocument("Template.docx", FormatType.Docx);
//Saves the Word document(.docx) as binary document(.doc) file
document.Save("DocxToBinary.doc", FormatType.Doc);
//Closes the document
document.Close();
'Loads an existing document
Dim document As New WordDocument("Template.docx", FormatType.Docx)
'Saves the Word document(.docx) as binary document(.doc) file 
document.Save("DocxToBinary.doc", FormatType.Doc)
'Closes the document
document.Close()

You can download a complete working sample from GitHub.

Word 97-2003 Template (DOT)

DOT is the binary template file format used in Word 97–Word 2003 and is used to create new documents from an existing template.

The following code example illustrates how to create a binary format document template with a few lines of code.

//Creates a new instance of WordDocument (Empty Word Document)
using (WordDocument document = new WordDocument())
{
    //Adds a section and a paragraph to the document
    document.EnsureMinimal();
    //Appends text to the last paragraph of the document
    document.LastParagraph.AppendText("Hello World");
    //Saves the Word document to MemoryStream
    MemoryStream stream = new MemoryStream();
    document.Save(stream, FormatType.Dot);
    //Closes the Word document
    document.Close();
}
//Creates an instance of WordDocument Instance (Empty Word Document)
WordDocument document = new WordDocument();
//Adds a section and a paragraph to the document
document.EnsureMinimal();
//Appends text to the last paragraph of the document
document.LastParagraph.AppendText("Hello World");
//Saves and closes the Word document
document.Save("Sample.dot");
document.Close();
'Creates an instance of WordDocument Instance (Empty Word Document)
Dim document As New WordDocument()
'Adds a section and a paragraph to the document
document.EnsureMinimal()
'Appends text to the last paragraph of the document
document.LastParagraph.AppendText("Hello World")
'Saves and closes the Word document
document.Save("Sample.dot")
document.Close()

You can download a complete working sample from GitHub.

Saving Word document with compatibility

Maintain existing compatibility

The following code example illustrates how to save a Word document with the same Word version compatibility.

//Creates an empty WordDocument instance
using (WordDocument document = new WordDocument())
{
    //Loads or opens an existing Word document from stream
    FileStream fileStreamPath = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
    //Loads or opens an existing Word document through Open method of WordDocument class 
    document.Open(fileStreamPath, FormatType.Automatic);
    //Enables flag to maintain compatibility with same Word version
    document.SaveOptions.MaintainCompatibilityMode = true;
    //Creates an instance of memory stream
    MemoryStream stream = new MemoryStream();
    //Saves the document to stream
    document.Save(stream, FormatType.Docx);
    //Closes the document
    document.Close();
}
//Opens an existing Word document
WordDocument document = new WordDocument("Template.docx");
//Enables flag to maintain compatibility with same Word version
document.SaveOptions.MaintainCompatibilityMode = true;
//Saves and closes the Word document
document.Save("Sample.docx");
document.Close();
'Opens an existing Word document
Dim document As WordDocument = New WordDocument("Template.docx")
'Enables flag to maintain compatibility with same Word version
document.SaveOptions.MaintainCompatibilityMode = true
'Saves and closes the Word document
document.Save("Sample.docx")
document.Close

You can download a complete working sample from GitHub.

Save Word in old compatibility

The following code example illustrates how to save a Word document in old compatibility using DocIO.

//Create an instance of WordDocument.
using (WordDocument document = new WordDocument())
{
    document.EnsureMinimal();
    //Appends paragraph.
    document.LastParagraph.AppendText("Hello World");
    //Sets the compatibility mode to Word 2007.
    document.Settings.CompatibilityMode = CompatibilityMode.Word2007;
    //Creates an instance of memory stream
    MemoryStream stream = new MemoryStream();
    //Saves the document to stream
    document.Save(stream, FormatType.Docx);
    //Closes the document
    document.Close();
}
//Create an instance of WordDocument.
using(WordDocument document = new WordDocument())
{
    document.EnsureMinimal();
    //Appends paragraph.
    document.LastParagraph.AppendText("Hello World");
    //Sets the compatibility mode to Word 2007.
    document.Settings.CompatibilityMode = CompatibilityMode.Word2007;
    //Saves and closes the Word document
    document.Save("Sample.docx");
    document.Close();
}
'Create an instance of WordDocument.
Using document As New WordDocument()
    document.EnsureMinimal()
    'Appends paragraph.
    document.LastParagraph.AppendText("Hello World")
    'Sets the compatibility mode to Word 2007.
    document.Settings.CompatibilityMode = CompatibilityMode.Word2007
    'Saves and closes the Word document
    document.Save("Sample.docx")
    document.Close()
End Using

You can download a complete working sample from GitHub.

Open a Word (*.doc) document containing incremental save information

Essential® DocIO process the content that are preserved in the last complete save operation alone from a Word (.doc) document and it doesn’t process the incremental save information. Hence it throws “Complex format is not supported” exception when attempting to open a Word (.doc) document containing incremental save information.

You can open the Word (*.doc) documents containing incremental save information without exception by setting SkipIncrementalSaveValidation property of Settings class as true. Whereas the recent changes saved as incremental save information using older Microsoft Word application can’t be preserved.

The following code example illustrates how to open a Word (*.doc) document containing incremental save information without exception.

//Creates a new instance of WordDocument (Empty Word Document)
using (WordDocument document = new WordDocument())
{
    //Loads or opens an existing Word document from stream
    FileStream fileStreamPath = new FileStream("Template.doc", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
    //Sets flag to skip old file format exception while opening document
    document.Settings.SkipIncrementalSaveValidation = true;
    //Loads or opens an existing Word document through Open method of WordDocument class 
    document.Open(fileStreamPath, FormatType.Automatic);
    MemoryStream stream = new MemoryStream();
    //Saves and closes the destination document to MemoryStream
    document.Save(stream, FormatType.Doc);
    document.Close();
}
//Creates an empty Word document instance
WordDocument document = new WordDocument();
//Sets flag to skip old file format exception while opening document
document.Settings.SkipIncrementalSaveValidation = true;
//Loads or opens an existing incrementally saved DOC format through Open method of WordDocument class
document.Open(fileName);
//Saves the Word Document
document.Save("Sample.doc", FormatType.Doc);
//Closes the document
document.Close();
'Creates an empty Word document instance
Dim document As New WordDocument()
'Sets flag to skip old file format exception while opening document
document.Settings.SkipIncrementalSaveValidation = True
'Loads or opens an existing incrementally saved DOC format through Open method of WordDocument class
document.Open(fileName)
'Saves the Word Document
document.Save("Sample.doc", FormatType.Doc)
'Closes the document
document.Close()

Online Demo

  • Explore how to convert the Word document to Word processing XML using the .NET Word Library (DocIO) in a live demo here.
  • See how to convert the Word processing XML to Word document using the .NET Word Library (DocIO) in a live demo here.