java.lang.Exception
com.aspose.words.IncorrectPasswordException
public class IncorrectPasswordException
To learn more, visit the Programming with Documents documentation article. Example:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("Hello world!");
DocSaveOptions options = new DocSaveOptions(SaveFormat.DOC);
// Set a password which will protect the loading of the document by Microsoft Word or Aspose.Words.
// Note that this does not encrypt the contents of the document in any way.
options.setPassword("MyPassword");
// If the document contains a routing slip, we can preserve it while saving by setting this flag to true.
options.setSaveRoutingSlip(true);
doc.save(getArtifactsDir() + "DocSaveOptions.SaveAsDoc.doc", options);
// To be able to load the document,
// we will need to apply the password we specified in the DocSaveOptions object in a LoadOptions object.
Assert.assertThrows(IncorrectPasswordException.class, () -> new Document(getArtifactsDir() + "DocSaveOptions.SaveAsDoc.doc"));
LoadOptions loadOptions = new LoadOptions("MyPassword");
doc = new Document(getArtifactsDir() + "DocSaveOptions.SaveAsDoc.doc", loadOptions);
Assert.assertEquals("Hello world!", doc.getText().trim());
See Also:
Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
Aspose.Words Support Forum - our preferred method of support.