DocumentProtect(ProtectionType) Method

Protects the document from changes without changing the existing password or assigns a random password.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.10.0


public void Protect(
	ProtectionType type


Type: Aspose.WordsProtectionType
Specifies the protection type for the document.


When a document is protected, the user can make only limited changes, such as adding annotations, making revisions, or completing a form.

When you protect a document, and the document already has a protection password, the existing protection password is not changed.

When you protect a document, and the document does not have a protection password, this method assigns a random password that makes it impossible to unprotect the document in Microsoft Word, but you still can unprotect the document in Aspose.Words as it does not require a password when unprotecting.


Shows how to protect a section so only editing in form fields is possible.
Document doc = new Document();

// Insert two sections with some text
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Section 1. Unprotected.");
builder.Writeln("Section 2. Protected.");

// Section protection only works when document protection is turned and only editing in form fields is allowed

// By default, all sections are protected, but we can selectively turn protection off
doc.Sections[0].ProtectedForForms = false;

doc.Save(ArtifactsDir + "Section.Protect.docx");

ExpandedSee Also