Password

OoxmlSaveOptions.Password property

Ruft ein Kennwort ab bzw. legt ein Kennwort fest, um das Dokument mit dem Standardverschlüsselungsalgorithmus ECMA376 zu verschlüsseln.

public string Password { get; set; }

Bemerkungen

Um das Dokument unverschlüsselt zu speichern, sollte diese Eigenschaftnull oder eine leere Zeichenfolge.

Beispiele

Zeigt, wie ein kennwortverschlüsseltes Office Open XML-Dokument erstellt wird.

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

// Wir können dieses Dokument nicht mit Microsoft Word öffnen oder
// Aspose.Words ohne Angabe des richtigen Passworts.
Assert.Throws<IncorrectPasswordException>(() =>
    doc = new Document(ArtifactsDir + "OoxmlSaveOptions.Password.docx"));

// Öffnen Sie das verschlüsselte Dokument, indem Sie das richtige Passwort in einem LoadOptions-Objekt übergeben.
doc = new Document(ArtifactsDir + "OoxmlSaveOptions.Password.docx", new LoadOptions("MyPassword"));

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

Siehe auch