Check if collection isn’t null (container extraction is supported for the document);
Iterate through the collection and get container item names, sizes and obtain content.
The following example shows how to extract a text from email attachments:
// Create an instance of Parser classusing(Parserparser=newParser(filePath)){// Extract attachments from the containerIEnumerable<ContainerItem>attachments=parser.GetContainer();// Check if container extraction is supportedif(attachments==null){Console.WriteLine("Container extraction isn't supported");}// Iterate over attachmentsforeach(ContainerItemiteminattachments){// Print the file pathConsole.WriteLine(item.FilePath);// Print metadataforeach(MetadataItemmetadatainitem.Metadata){Console.WriteLine(string.Format("{0}: {1}",metadata.Name,metadata.Value));}try{// Create Parser object for the email contentusing(ParserattachmentParser=item.OpenParser()){// Extract an email textusing(TextReaderreader=attachmentParser.GetText()){Console.WriteLine(reader==null?"No text":reader.ReadToEnd());}}}catch(UnsupportedDocumentFormatException){Console.WriteLine("Isn't supported.");}}}
Detect inline images
To detect if image attachment is inline ‘disposition’ metadata is used. If it’s present, it can take ‘inline’ or ‘attachment’ values.
The following example shows how to detect inline attachments:
// Create an instance of Parser classusing(Parserparser=newParser(filePath)){// Extract attachments from the containerIEnumerable<ContainerItem>attachments=parser.GetContainer();// Check if container extraction is supportedif(attachments==null){Console.WriteLine("Container extraction isn't supported");}// Iterate over attachmentsforeach(ContainerItemiteminattachments){// Check metadata for 'disposition' itemif(item.GetMetadataValue("disposition")=="inline"){// If it's 'inline' then print the file pathConsole.WriteLine(item.FilePath);}}}
More resources
GitHub examples
You may easily run the code above and see the feature in action in our GitHub examples:
Along with full featured .NET library we provide simple, but powerful free Apps.
You are welcome to parse documents and extract data from PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, Emails and more with our free online Free Online Document Parser App.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.