GroupDocs.Parser provides the functionality to detect a file type of container items by DetectFileType method. FileTypeDetectionMode parameter provides the ability to control file type detection:
Default. The file type is detected by the file extension; if the file extension isn’t recognized, the file type is detected by the file content.
Extension. The file type is detected only by the file extension.
Content. The file type is detected only by the file content.
Here are the steps to detect a file type of container items:
Instantiate Parser object for the initial document;
Check if collection isn’t null (container extraction is supported for the document);
Iterate through the collection and call DetectFileType method.
The following example shows how to detect a file type of container items:
// 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){// Detect the file typeOptions.FileTypefileType=item.DetectFileType(Options.FileTypeDetectionMode.Default);// Print the name and file typeConsole.WriteLine(string.Format("{0}: {1}",item.Name,fileType));}}
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.