ContainerItemDetectFileType Method
Detects a file type of the container item.

Namespace: GroupDocs.Parser.Data
Assembly: GroupDocs.Parser (in GroupDocs.Parser.dll) Version: 20.10.0
Syntax
public FileType DetectFileType(
	FileTypeDetectionMode detectionMode
)

Parameters

detectionMode
Type: GroupDocs.Parser.OptionsFileTypeDetectionMode
Defines a mode of the file type detection.

Return Value

Type: FileType
An instance of FileType class; Unknown if a file type isn't detected.
Remarks

detectionMode 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.
Examples

The following example shows how to detect file type of container item:

C#
// Create an instance of Parser class
using (Parser parser = new Parser(filePath))
{
    // Extract attachments from the container
    IEnumerable<ContainerItem> attachments = parser.GetContainer();
    // Check if container extraction is supported
    if (attachments == null)
    {
        Console.WriteLine("Container extraction isn't supported");
    }
    // Iterate over attachments
    foreach (ContainerItem item in attachments)
    {
        // Detect the file type
        Options.FileType fileType = item.DetectFileType(Options.FileTypeDetectionMode.Default);

        // Print the name and file type
        Console.WriteLine(string.Format("{0}: {1}", item.Name, fileType));
    }
}
See Also