WriteProtectionIsWriteProtected Property |
Namespace: Aspose.Words.Settings
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.");