Document Constructor (Stream, LoadOptions)
Opens an existing document from a stream. Allows to specify additional options such as an encryption password.

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.9
Syntax
public Document(
	Stream stream,
	LoadOptions loadOptions
)

Parameters

stream
Type: System.IOStream
The stream where to load the document from.
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.
ArgumentNullExceptionThe stream cannot be null.
NotSupportedExceptionThe stream does not support reading or seeking.
ObjectDisposedExceptionThe stream is a disposed object.
Remarks
Remarks

The document must be stored at the beginning of the stream. The stream must support random positioning.

Examples
Loads a Microsoft Word document encrypted with a password from a stream.
[C#]

using (Stream stream = File.OpenRead(MyDir + "Document.LoadEncrypted.doc"))
{
    Document doc = new Document(stream, new LoadOptions("qwerty"));
}
Examples
Opens an HTML document with images from a stream using a base URI.
[C#]

Document doc = new Document();
// We are opening this HTML file:      
//    <html>
//    <body>
//    <p>Simple file.</p>
//    <p><img src="Aspose.Words.gif" width="80" height="60"></p>
//    </body>
//    </html>
String fileName = MyDir + "Document.OpenFromStreamWithBaseUri.html";
// Open the stream.
using (Stream stream = File.OpenRead(fileName))
{
    // Open the document. Note the Document constructor detects HTML format automatically.
    // Pass the URI of the base folder so any images with relative URIs in the HTML document can be found.
    LoadOptions loadOptions = new LoadOptions();
    loadOptions.BaseUri = MyDir;

    doc = new Document(stream, loadOptions);
}

// Save in the DOC format.
doc.Save(ArtifactsDir + "Document.OpenFromStreamWithBaseUri.doc");
Examples
Shows how to insert the HTML contents from a web page into a new document.
[C#]

// The url of the page to load 
String url = "http://www.aspose.com/";

// Create a WebClient object to easily extract the HTML from the page.
WebClient client = new WebClient();
String pageSource = client.DownloadString(url);
client.Dispose();

// Get the HTML as bytes for loading into a stream.
Encoding encoding = client.Encoding;
byte[] pageBytes = encoding.GetBytes(pageSource);

// Load the HTML into a stream.
using (MemoryStream stream = new MemoryStream(pageBytes))
{
    // The baseUri property should be set to ensure any relative img paths are retrieved correctly.
    LoadOptions options = new LoadOptions(Aspose.Words.LoadFormat.Html, "", url);

    // Load the HTML document from stream and pass the LoadOptions object.
    Document doc = new Document(stream, options);

    // Save the document to disk.
    // The extension of the filename can be changed to save the document into other formats. e.g PDF, DOCX, ODT, RTF.
    doc.Save(ArtifactsDir + "Document.HtmlPageFromWebpage.doc");
}
See Also