Document(String, LoadOptions) Constructor

Opens an existing document from a file. Allows to specify additional options such as an encryption password.

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

Syntax

public Document(
	string fileName,
	LoadOptions loadOptions
)

Parameters

fileName
Type: SystemString
File name of the document to open.
loadOptions
Type: Aspose.WordsLoadOptions
Additional options to use when loading a document. Can be null.

Exceptions

ExceptionCondition
UnsupportedFileFormatExceptionThe document format is not recognized or not supported.
FileCorruptedExceptionThe document appears to be corrupted and cannot be loaded.
ExceptionThere is a problem with the document and it should be reported to Aspose.Words developers.
IOExceptionThere is an input/output exception.
IncorrectPasswordExceptionThe document is encrypted and requires a password to open, but you supplied an incorrect password.
ArgumentExceptionThe name of the file cannot be null or empty string.

Examples

Shows how to load a document as HTML without automatic file format detection.
LoadOptions loadOptions = new LoadOptions();
loadOptions.LoadFormat = Aspose.Words.LoadFormat.Html;

Document doc = new Document(MyDir + "Document.html", loadOptions);
Shows how to load a Microsoft Word document encrypted with a password.
// If we try open an encrypted document without the password, an IncorrectPasswordException will be thrown
// We can construct a LoadOptions object with the correct encryption password
LoadOptions options = new LoadOptions("docPassword");

// Then, we can use that object as a parameter when opening an encrypted document
Document doc = new Document(MyDir + "Encrypted.docx", options);

using (Stream stream = File.OpenRead(MyDir + "Encrypted.docx"))
{
    doc = new Document(stream, options);
}

See Also