OoxmlSaveOptionsPassword Property

Gets/sets a password to encrypt document using ECMA376 Standard encryption algorithm.

Namespace:  Aspose.Words.Saving
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 21.6.0

ExpandedSyntax

public string Password { get; set; }

Property Value

Type: String

ExpandedRemarks

In order to save document without encryption this property should be null or empty string.

ExpandedExamples

Shows how to create a password encrypted Office Open XML document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Hello world!");

OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
saveOptions.Password = "MyPassword";

doc.Save(ArtifactsDir + "OoxmlSaveOptions.Password.docx", saveOptions);

// We will not be able to open this document with Microsoft Word or
// Aspose.Words without providing the correct password.
Assert.Throws<IncorrectPasswordException>(() =>
    doc = new Document(ArtifactsDir + "OoxmlSaveOptions.Password.docx"));

// Open the encrypted document by passing the correct password in a LoadOptions object.
doc = new Document(ArtifactsDir + "OoxmlSaveOptions.Password.docx", new LoadOptions("MyPassword"));

Assert.AreEqual("Hello world!", doc.GetText().Trim());

ExpandedSee Also