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.

DOCX Write Protection

DOCX Write Protection refers to a mode in which the document's contents can be edited but the document cannot be resaved using the same file name.

Following example shows how to create write protected DOCX file.

Screenshot
DOCX Write Protection Screenshot

See the full code below, use Run Example to execute.

using System;
using GemBox.Document;
using GemBox.Document.Drawing;
using System.IO;
using System.Linq;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        DocumentModel document = new DocumentModel();

        var section = new Section(document);
        document.Sections.Add(section);

        Paragraph paragraph1 = new Paragraph(document, "This document has been opened in read-only mode. Changes cannot be made to the original document. To save changes, create a new copy of the document.");
        section.Blocks.Add(paragraph1);

        Paragraph paragraph2 = new Paragraph(document, "To enable modifying use password: 1234");
        section.Blocks.Add(paragraph2);

        WriteProtection protection = document.WriteProtection;
        // For DOCX file format: disallow resaving the document using the same file name.
        protection.SetPassword("1234");

        document.Save("DOCX Write Protection.docx");
    }
}
Imports System
Imports GemBox.Document
Imports GemBox.Document.Drawing
Imports System.IO
Imports System.Linq

Module Samples

    Sub Main()

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

        Dim document As DocumentModel = New DocumentModel

        Dim section = New Section(document)
        document.Sections.Add(section)

        Dim paragraph1 = New Paragraph(document, "This document has been opened in read-only mode. Changes cannot be made to the original document. To save changes, create a new copy of the document.")
        section.Blocks.Add(paragraph1)

        Dim paragraph2 = New Paragraph(document, "To enable modifying use password: 1234")
        section.Blocks.Add(paragraph2)

        Dim protection = document.WriteProtection
        ' For DOCX file format: disallow resaving the document using the same file name.
        protection.SetPassword("1234")

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

    End Sub

End Module

Check next sample.