WriteProtectionIsWriteProtected Property

Returns true when a write protection password is set.

Namespace:  Aspose.Words.Settings
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public bool IsWriteProtected { get; }

Property Value

Type: Boolean
Examples
Shows how to protect a document with a password.
Document doc = new Document();
Assert.IsFalse(doc.WriteProtection.IsWriteProtected);
Assert.IsFalse(doc.WriteProtection.ReadOnlyRecommended);

// Enter a password that's 15 or less characters long
doc.WriteProtection.SetPassword("docpassword123");
Assert.IsTrue(doc.WriteProtection.IsWriteProtected);

Assert.IsFalse(doc.WriteProtection.ValidatePassword("wrongpassword"));

DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("We can still edit the document at this stage.");

// Save the document
// Without the password, we can only read this document in Microsoft Word
// With the password, we can read and write
doc.Save(ArtifactsDir + "Document.WriteProtection.docx");

// Re-open our document
Document docProtected = new Document(ArtifactsDir + "Document.WriteProtection.docx");
DocumentBuilder docProtectedBuilder = new DocumentBuilder(docProtected);
docProtectedBuilder.MoveToDocumentEnd();

// We can programmatically edit this document without using our password
// However, if we wish to edit it in Microsoft Word, we will need the password to open it
Assert.IsTrue(docProtected.WriteProtection.IsWriteProtected);
docProtectedBuilder.Writeln("Writing text in a protected document.");
See Also