Open

Open(string)

Allows a COM application to load a Document from a file.

public Document Open(string fileName)
ParameterTypeDescription
fileNameStringFilename of the document to load.

Return Value

A Document object that represents a Word document.

Remarks

This method is same as calling the Document constructor with a file name parameter.

Examples

[VBScript]

Dim helper
Set helper = CreateObject("Aspose.Words.ComHelper")

Dim doc
Set doc = helper.Open(fileName)

Shows how to open documents using the ComHelper class.

// The ComHelper class allows us to load documents from within COM clients.
ComHelper comHelper = new ComHelper();

// 1 -  Using a local system filename:
Document doc = comHelper.Open(MyDir + "Document.docx");

Assert.AreEqual("Hello World!\r\rHello Word!\r\r\rHello World!", doc.GetText().Trim());

// 2 -  From a stream:
using (FileStream stream = new FileStream(MyDir + "Document.docx", FileMode.Open))
{
    doc = comHelper.Open(stream);

    Assert.AreEqual("Hello World!\r\rHello Word!\r\r\rHello World!", doc.GetText().Trim());
}

See Also


Open(Stream)

Allows a COM application to load Document from a stream.

public Document Open(Stream stream)
ParameterTypeDescription
streamStreamA .NET stream object that contains the document to load.

Return Value

A Document object that represents a Word document.

Remarks

This method is same as calling the Document constructor with a stream parameter.

Examples

Shows how to open documents using the ComHelper class.

// The ComHelper class allows us to load documents from within COM clients.
ComHelper comHelper = new ComHelper();

// 1 -  Using a local system filename:
Document doc = comHelper.Open(MyDir + "Document.docx");

Assert.AreEqual("Hello World!\r\rHello Word!\r\r\rHello World!", doc.GetText().Trim());

// 2 -  From a stream:
using (FileStream stream = new FileStream(MyDir + "Document.docx", FileMode.Open))
{
    doc = comHelper.Open(stream);

    Assert.AreEqual("Hello World!\r\rHello Word!\r\r\rHello World!", doc.GetText().Trim());
}

See Also