DocumentWriteProtection Property

Provides access to the document write protection options.

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

Syntax

public WriteProtection WriteProtection { get; }

Property Value

Type: WriteProtection

Examples

Shows how to protect a document with a password.
Document doc = new Document();

// Enter a password that's up to 15 characters long
doc.WriteProtection.SetPassword("MyPassword");

Assert.IsTrue(doc.WriteProtection.IsWriteProtected);
Assert.IsTrue(doc.WriteProtection.ValidatePassword("MyPassword"));

// This flag applies to RTF documents and will be ignored by Microsoft Word
doc.WriteProtection.ReadOnlyRecommended = true;

DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Write protection does not prevent us from editing the document programmatically.");

// 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");

See Also