DocumentUnprotect Method

Removes protection from the document regardless of the password.

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

Syntax

public void Unprotect()

Remarks

This method unprotects the document even if it has a protection password.

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

Examples

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
doc.Unprotect();
Assert.AreEqual(ProtectionType.NoProtection, doc.ProtectionType);

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

See Also