Document(String) Constructor

Opens an existing document from a file. Automatically detects the file format.

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

Syntax

public Document(
	string fileName
)

Parameters

fileName
Type: SystemString
File name of the document to open.

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 open a document and convert it to .PDF.
// Open a document that exists in the local file system
Document doc = new Document(MyDir + "Document.docx");

// Save that document as a PDF to another location
doc.Save(ArtifactsDir + "Document.ConvertToPdf.pdf");

See Also