Edit and save Word file in C# and VB.NET

Edit and save Word file (DOCX) in C# and VB.NET with GemBox.Document component.

GemBox.Document is a C# / VB.NET component that enables developers to read, write, convert and print document files (DOCX, DOC, PDF, HTML, XPS, TXT) from .NET applications in a simple and efficient way without the need for Microsoft Word on either the developer or client machines.
GemBox.Document Free is free of charge while GemBox.Document Professional is a commercial version licensed per developer.
For more information, see GemBox.Document features and why GemBox.Document outperforms Word automation.

Following example edits a document by clearing all text formatting, saves it to a Word file (DOCX) and opens it with Microsoft Word.

C# code

// Load a document.
var document = DocumentModel.Load("Document.docx");

// Iterate over all runs in the document and clear their formatting.
foreach (Run run in document.GetChildElements(true, ElementType.Run))
run.CharacterFormat.ClearFormatting();

// Save the document to a file.
document.Save("Document.docx");

// Open the document file with Microsoft Word.
Process.Start("Document.docx");

VB.NET code

' Load a document.
Dim document = DocumentModel.Load("Document.docx")

' Iterate over all runs in the document and clear their formatting.
For Each run As Run In document.GetChildElements(True, ElementType.Run)
run.CharacterFormat.ClearFormatting()
Next

' Save the document to a file.
document.Save("Document.docx")

' Open the document file with Microsoft Word.
Process.Start("Document.docx")

For a more detailed example, see Template Use sample from GemBox.Document Sample Explorer.