FileFormatUtilDetectFileFormat Method (String) |
Namespace: Aspose.Words
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.
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);
// 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)); }