/// <summary> /// Creates an TextReader object for the given <paramref name="fileName"/> /// </summary> /// <param name="fileName">The file to read</param> /// <param name="extension">Overrides the file extension of the <paramref name="fileName"/>, /// the extension is used to determine the <see cref="NativeMethods.IFilter"/> that needs to /// be used to read the <paramref name="fileName"/></param> /// <param name="disableEmbeddedContent">When set to <c>true</c> the <see cref="NativeMethods.IFilter"/> /// doesn't read embedded content, e.g. an attachment inside an E-mail msg file. This parameter is default set to <c>false</c></param> /// <param name="includeProperties">When set to <c>true</c> the metadata properties of /// a document are also returned, e.g. the summary properties of a Word document. This parameter /// is default set to <c>false</c></param> /// <param name="readIntoMemory">When set to <c>true</c> the <paramref name="fileName"/> is completely read /// into memory first before the iFilters starts to read chunks, when set to <c>false</c> the iFilter reads /// directly from the <paramref name="fileName"/> and advances reading when the chunks are returned. /// Default set to <c>false</c></param> public FilterReader(string fileName, string extension = "", bool disableEmbeddedContent = false, bool includeProperties = false, bool readIntoMemory = false) { try { _fileName = fileName; _fileStream = File.OpenRead(fileName); if (string.IsNullOrWhiteSpace(extension)) extension = Path.GetExtension(fileName); _filter = FilterLoader.LoadAndInitIFilter(_fileStream, extension, disableEmbeddedContent, fileName, readIntoMemory); if (_filter == null) { if (string.IsNullOrWhiteSpace(extension)) throw new IFFilterNotFound("There is no " + (Environment.Is64BitProcess ? "64" : "32") + " bits IFilter installed for the file '" + Path.GetFileName(fileName) + "'"); throw new IFFilterNotFound("There is no " + (Environment.Is64BitProcess ? "64" : "32") + " bits IFilter installed for the extension '" + extension + "'"); } _includeProperties = includeProperties; } catch (Exception) { Dispose(); throw; } }
/// <summary> /// Creates an TextReader object for the given <see cref="Stream"/> /// </summary> /// <param name="stream">The file stream to read</param> /// <param name="extension">The extension for the <paramref name="stream"/></param> /// <param name="disableEmbeddedContent">When set to <c>true</c> the <see cref="NativeMethods.IFilter"/> /// doesn't read embedded content, e.g. an attachment inside an E-mail msg file. This parameter is default set to <c>false</c></param> /// <param name="includeProperties">When set to <c>true</c> the metadata properties of /// a document are also returned, e.g. the summary properties of a Word document. This parameter /// is default set to <c>false</c></param> /// <param name="readIntoMemory">When set to <c>true</c> the <paramref name="stream"/> is completely read /// into memory first before the iFilters starts to read chunks, when set to <c>false</c> the iFilter reads /// directly from the <paramref name="stream"/> and advances reading when the chunks are returned. /// Default set to <c>false</c></param> public FilterReader(Stream stream, string extension, bool disableEmbeddedContent = false, bool includeProperties = false, bool readIntoMemory = false) { if (string.IsNullOrWhiteSpace(extension)) throw new ArgumentException("The extension cannot be empty", "extension"); _filter = FilterLoader.LoadAndInitIFilter(stream, extension, disableEmbeddedContent, string.Empty, readIntoMemory); if (_filter == null) throw new IFFilterNotFound("There is no " + (Environment.Is64BitProcess ? "64" : "32") + " bits IFilter installed for the stream with the extension '" + extension + "'"); _includeProperties = includeProperties; }