Document Constructor (Stream)
Opens an existing document from a stream. Automatically detects the file format.

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.11
Syntax
public Document(
	Stream stream
)

Parameters

stream
Type: System.IOStream
Stream where to load the document from.
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
Opens a document from a stream.
// Open the stream. Read only access is enough for Aspose.Words to load a document.
using (Stream stream = File.OpenRead(MyDir + "Document.doc"))
{
    // Load the entire document into memory.
    Document doc = new Document(stream);
}
// ... do something with the document
Examples
Retrieves a document from a URL and saves it to disk in a different format.
// This is the URL address pointing to where to find the document.
String url = "https://is.gd/URJluZ";
// The easiest way to load our document from the internet is make use of the 
// System.Net.WebClient class. Create an instance of it and pass the URL
// to download from.
using (WebClient webClient = new WebClient())
{
    // Download the bytes from the location referenced by the URL.
    byte[] dataBytes = webClient.DownloadData(url);

    // Wrap the bytes representing the document in memory into a MemoryStream object.
    using (MemoryStream byteStream = new MemoryStream(dataBytes))
    {
        // Load this memory stream into a new Aspose.Words Document.
        // The file format of the passed data is inferred from the content of the bytes itself. 
        // You can load any document format supported by Aspose.Words in the same way.
        Document doc = new Document(byteStream);

        // Convert the document to any format supported by Aspose.Words.
        doc.Save(ArtifactsDir + "Document.OpenFromWeb.docx");
    }
}
See Also