DocumentProtectionType Property

Gets the currently active document protection type.

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


public ProtectionType ProtectionType { get; }

Property Value

Type: ProtectionType


This property allows to retrieve the currently set document protection type. To change the document protection type use the Protect(ProtectionType, String) and Unprotect methods.

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

Note that document protection is different from write protection. Write protection is specified using the WriteProtection


Shows how to protect a document.
// Create a new document and protect it with a password
Document doc = new Document();
doc.Protect(ProtectionType.ReadOnly, "password");
Assert.AreEqual(ProtectionType.ReadOnly, doc.ProtectionType);

// If we open this document with Microsoft Word and wish to edit it, 
// we will first need to stop the protection, which can only be done with the password
doc.Save(ArtifactsDir + "Document.Protect.docx");

// Note that the protection only applies to Microsoft Word users opening out document
// The document can still be opened and edited programmatically without a password, despite its protection status
// Encryption offers a more robust option for protecting document content
Document protectedDoc = new Document(ArtifactsDir + "Document.Protect.docx");
Assert.AreEqual(ProtectionType.ReadOnly, protectedDoc.ProtectionType);

DocumentBuilder builder = new DocumentBuilder(protectedDoc);
builder.Writeln("Text added to a protected document.");

// Documents can have protection removed either with no password, or with the correct password
Assert.AreEqual(ProtectionType.NoProtection, doc.ProtectionType);

doc.Protect(ProtectionType.ReadOnly, "newPassword");
Assert.AreEqual(ProtectionType.NoProtection, doc.ProtectionType);

See Also