This article describes how to load input document to the GroupDocs.Editor and how to apply load options.
First of all the input document, which should be accessible as a byte stream or through valid file path, should be loaded into the GroupDocs.Editor by creating an instance of the Editor class through one of the constructor overloads.
If the input document is presented as a stream, it should be loaded through delegate. Source code below shows two ways of loading documents: from path and from stream.
//through pathstringinputFilePath="C:\\input_path\\document.docx";//path to some documentEditoreditor=newEditor(inputFilePath);//through streamFileStreaminputStream=System.IO.File.OpenRead(inputFilePath);Editoreditor=newEditor(delegate{returninputStream;});
When two overloads from example above are used, GroupDocs.Editor automatically detects the format of input document and applies the most appropriate default loading options for the input document.
However, it is possible and even recommended to specify correct loading options explicitly using constructor overloads, which accept two parameters. Like streams, loading options should be specified through delegates.
Source code below shows using such options.
//through pathstringinputFilePath="C:\\input_path\\document.docx";//path to some documentWordProcessingLoadOptionswordLoadOptions=newWordProcessingLoadOptions();Editoreditor=newEditor(inputFilePath,delegate{returnwordLoadOptions;});//passing path and load options (via delegate) to the constructor//through streamMemoryStreaminputStream=newMemoryStream();//obtained from somewhereSpreadsheetLoadOptionsspreadsheetLoadOptions=newSpreadsheetLoadOptions();Editoreditor=newEditor(delegate{returninputStream;},delegate{returnspreadsheetLoadOptions;});
Please note that not all document formats have appropriate classes, that represent load options. As for version 22.7, only WordProcessing, Spreadsheet and Presentation family formats, as well as a distinct PDF format, have load options. For other document formats, such as DSV, TXT or XML, there are no load options.
Using load options is the only way for working with password-protected input documents. Any document can be loaded into the Editor instance, even encoded document without the password. However, on the next step — opening for editing, — the exception will be thrown. GroupDocs.Editor handles passwords and encoded documents in the next way:
If document is not encoded, password is ignored anyway, whether or not it was specified.
If document is password-protected, but password is not specified, the PasswordRequiredException will be thrown later during editing.
If document is password-protected, and password is specified, but is incorrect, the IncorrectPasswordException will be thrown later during editing.
Example below shows specifying password for opening some password-protected WordProcessing document.