FileFormatUtilDetectFileFormat Method (String)

Detects and returns the information about a format of a document stored in a disk file.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public static FileFormatInfo DetectFileFormat(
	string fileName
)

Parameters

fileName
Type: SystemString
The file name.

Return Value

Type: FileFormatInfo
A FileFormatInfo object that contains the detected information.
Remarks

Even if this method detects the document format, it does not guarantee that the specified document is valid. This method only detects the document format by reading data that is sufficient for detection. To fully verify that a document is valid you need to load the document into a Document object.

This method throws FileCorruptedException when the format is recognized, but the detection cannot complete because of corruption.

Examples
Shows how to use the FileFormatUtil class to detect the document format and other features of the document.
FileFormatInfo info = FileFormatUtil.DetectFileFormat(MyDir + "Document.docx");
Console.WriteLine("The document format is: " + FileFormatUtil.LoadFormatToExtension(info.LoadFormat));
Console.WriteLine("Document is encrypted: " + info.IsEncrypted);
Console.WriteLine("Document has a digital signature: " + info.HasDigitalSignature);
Examples
Shows how to check a document for digital signatures before loading it into a Document object.
// The path to the document which is to be processed
string filePath = MyDir + "Digitally signed.docx";

FileFormatInfo info = FileFormatUtil.DetectFileFormat(filePath);
if (info.HasDigitalSignature)
{
    Console.WriteLine(
        "Document {0} has digital signatures, they will be lost if you open/save this document with Aspose.Words.",
        Path.GetFileName(filePath));
}
See Also