Output adapters

Output adapters are used to output generated HTML text to various output objects. The following output adapters are currently supported:

  • FileOutputAdapter is an output adapter that is used to output text to a file. The path to a file is specified in the constructor of the adapter.
  • StreamOutputAdapter is an output adapter that is used to output text to a stream. The stream is specified in the constructor of the adapter.
  • StringOutputAdapter is an output adapter that is used to output text to a string. The resulting string can be accessed through the GetResult method of the adapter class.

The example below demonstates how to use adapters of different types.

C#

string indexFolder = @"c:\MyIndex\";
string documentsFolder = @"c:\MyDocuments\";
 
// Creating an index in the specified folder
Index index = new Index(indexFolder);
 
// Indexing documents from the specified folder
index.Add(documentsFolder);
 
// Getting list of indexed documents
DocumentInfo[] documents = index.GetIndexedDocuments();
 
// Getting a document text
if (documents.Length > 0)
{
    DocumentInfo document = documents[0];
 
    // Output to a file
    FileOutputAdapter fileOutputAdapter = new FileOutputAdapter(@"C:\Text.html");
    index.GetDocumentText(document, fileOutputAdapter);
 
    // Output to a stream
    using (Stream stream = new MemoryStream())
    {
        StreamOutputAdapter streamOutputAdapter = new StreamOutputAdapter(stream);
        index.GetDocumentText(document, streamOutputAdapter);
    }
 
    // Output to a string
    StringOutputAdapter stringOutputAdapter = new StringOutputAdapter();
    index.GetDocumentText(document, stringOutputAdapter);
    string result = stringOutputAdapter.GetResult();
}

More resources

GitHub examples

You may easily run the code from documentation articles and see the features in action in our GitHub examples:

Free online document search App

Along with full featured .NET library we provide simple, but powerful free Apps.

You are welcome to search over your PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX and more with our free online Free Online Document Search App.