DOCX Write Protection

DOCX write protection enables you to lock your original Word document to prevent any changes being made to it.

A Word file with write protection is opened in Word applications with a Read-Only mode. The document's content can be edited, but it cannot be re-saved with the same file name.

Note, with GemBox.Document you can modify the original Word document even if it has write protection.

The following example shows how you create a write protected DOCX file using the WriteProtection class.

Write protected Word file of DOCX format created in C# and VB.NET and opened in read-only mode.
Screenshot of write protected Word document
using GemBox.Document;

class Program
{
    static void Main()
    {
        // If using the Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var document = new DocumentModel();

        document.Sections.Add(
            new Section(document,
                new Paragraph(document, "This document has been opened in read-only mode."),
                new Paragraph(document, "Changes cannot be made to the original document."),
                new Paragraph(document, "To save changes a new copy of the document must be created.")));

        WriteProtection protection = document.WriteProtection;
        protection.SetPassword("pass");

        document.Save("DOCX Write Protection.docx");
    }
}
Imports GemBox.Document

Module Program

    Sub Main()

        ' If using the Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim document As New DocumentModel()

        document.Sections.Add(
            New Section(document,
                New Paragraph(document, "This document has been opened in read-only mode."),
                New Paragraph(document, "Changes cannot be made to the original document."),
                New Paragraph(document, "To save changes a new copy of the document must be created.")))

        Dim protection As WriteProtection = document.WriteProtection
        protection.SetPassword("pass")

        document.Save("DOCX Write Protection.docx")

    End Sub
End Module

See also


Next steps

GemBox.Document is a .NET component that enables you to read, write, edit, convert, and print document files from your .NET applications using one simple API. How about testing it today?

Download Buy