# Filter in File or Stream Mode

To filter files using the methods in the `Filter` class

1. Instantiate a `Filter` object using either the default constructor or the constructor that sets the output character set and filter flags:

   1. Use the default constructor `Filter().` For example:

          objFilter = new Filter();

   2. Use the constructor `Filter(string OutputCharSet, UInt32 filterFlags)`. For example:

          objFilter = new Filter(outputCharSet, FilterConstant.FilterFlagConstant.FILTERFLAG_OOPLOGON);

   The Filter flags provide instructions on how to process a file or stream. For example, they specify whether an error log is generated during filtering (`FILTERFLAG_OOPLOGON`) or whether headers and footers are extracted from the document (`FILTERFLAG_HEADERFOOTERTAGS`).

   NOTE: Filter runs out of process by default. See The Filter Process Model for more information.

2. Set the location of the Filter libraries by using the `FilterDirectory` property. These libraries are normally stored in the directory `install\OS\bin`, where `install` is the path name of the Filter installation directory and `OS` is the name of the operating system. For example:

       objFilter.FilterDirectory = filterDir;

3. Set the input source as either a file or input stream by calling the `SetInputSource` method.

       objFilter.SetInputSource(m_inFile);

4. Filter the file or stream by calling either the `FilterTo` or `DoFilterChunk` method. The `FilterTo` method extracts the data to a file or a stream. The `DoFilterChunk` method extracts one chunk of data from a file or a stream. It must be called repeatedly until the entire buffer is filtered.

   If filtering in file mode, use the following code:

          {
            m_objFilter.filterTo(m_extractDir + filename + m_extension);
          }

   If filtering in stream mode, use the following code:

           {
            outf = new File(m_extractDir + filename + m_extension);
            fos = new FileOutputStream(outf);
            m_objFilter.filterTo(fos);
            fos.close();
           }

5. Terminate the filtering session and free allocated system resources by calling the `ShutdownFilter()` method. This must be called within a `Finally` block.

       m_objFilter.ShutdownFilter();

© Copyright 2016-2020 Micro Focus or one of its affiliates | Send documentation feedback Close Send documentation feedback To open the configured email client on this computer, open an email window. Otherwise, copy the information below to a mail client, and then send this email to swpdl.idoldocsfeedback@microfocus.com. We appreciate your feedback! Product: Topic Title: Help Topic: Feedback:

_FT_HTML5_bannerTitle.htm