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.


1using System;
2using GemBox.Document;
3using GemBox.Document.Drawing;
4using System.IO;
5using System.Linq;
6
7class Sample
8{
9    [STAThread]
10    static void Main(string[] args)
11    {
12        // If using Professional version, put your serial key below.
13        ComponentInfo.SetLicense("FREE-LIMITED-KEY");
14
15        DocumentModel document = new DocumentModel();
16
17        var section = new Section(document);
18        document.Sections.Add(section);
19
20        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.");
21        section.Blocks.Add(paragraph1);
22
23        Paragraph paragraph2 = new Paragraph(document, "To enable modifying use password: 1234");
24        section.Blocks.Add(paragraph2);
25
26        WriteProtection protection = document.WriteProtection;
27        // For DOCX file format: disallow resaving the document using the same file name.
28        protection.SetPassword("1234");
29
30        document.Save("DOCX Write Protection.docx");
31    }
32}
1Imports System
2Imports GemBox.Document
3Imports GemBox.Document.Drawing
4Imports System.IO
5Imports System.Linq
6
7Module Samples
8
9    Sub Main()
10
11        ' If using Professional version, put your serial key below.
12        ComponentInfo.SetLicense("FREE-LIMITED-KEY")
13
14        Dim document As DocumentModel = New DocumentModel
15
16        Dim section = New Section(document)
17        document.Sections.Add(section)
18
19        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.")
20        section.Blocks.Add(paragraph1)
21
22        Dim paragraph2 = New Paragraph(document, "To enable modifying use password: 1234")
23        section.Blocks.Add(paragraph2)
24
25        Dim protection = document.WriteProtection
26        ' For DOCX file format: disallow resaving the document using the same file name.
27        protection.SetPassword("1234")
28
29        document.Save("DOCX Write Protection.docx")
30
31    End Sub
32
33End Module

Check next sample or find out more about GemBox.Document and GemBox Software.