FileFormatInfo Class

Contains data returned by FileFormatUtil document format detection methods.

ExpandedInheritance Hierarchy

SystemObject
  Aspose.WordsFileFormatInfo

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.11.0

ExpandedSyntax

public class FileFormatInfo

The FileFormatInfo type exposes the following members.

ExpandedProperties

  NameDescription
Public propertyCode exampleEncoding
Gets the detected encoding if applicable to the current document format. At the moment detects encoding only for HTML documents.
Public propertyCode exampleHasDigitalSignature
Returns true if this document contains a digital signature. This property merely informs that a digital signature is present on a document, but it does not specify whether the signature is valid or not.
Public propertyCode exampleIsEncrypted
Returns true if the document is encrypted and requires a password to open.
Public propertyCode exampleLoadFormat
Gets the detected document format.

ExpandedMethods

  NameDescription
Public methodEquals (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodToString (Inherited from Object.)

ExpandedRemarks

You do not create instances of this class directly. Objects of this class are returned by DetectFileFormat(Stream) methods.

ExpandedExamples

Shows how to use the FileFormatUtil class to detect the document format and encryption.
Document doc = new Document();

// Save it as an encrypted .odt
OdtSaveOptions saveOptions = new OdtSaveOptions(SaveFormat.Odt);
saveOptions.Password = "MyPassword";

doc.Save(ArtifactsDir + "File.DetectDocumentEncryption.odt", saveOptions);

// Create a FileFormatInfo object for this document
FileFormatInfo info = FileFormatUtil.DetectFileFormat(ArtifactsDir + "File.DetectDocumentEncryption.odt");

// Verify the file type of our document and its encryption status
Assert.AreEqual(".odt", FileFormatUtil.LoadFormatToExtension(info.LoadFormat));
Assert.True(info.IsEncrypted);
Shows how to use the FileFormatUtil class to detect the document format and presence of digital signatures.
// Use a FileFormatInfo instance to verify that a document is not digitally signed
FileFormatInfo info = FileFormatUtil.DetectFileFormat(MyDir + "Document.docx");

Assert.AreEqual(".docx", FileFormatUtil.LoadFormatToExtension(info.LoadFormat));
Assert.False(info.HasDigitalSignature);

// Sign the document
CertificateHolder certificateHolder = CertificateHolder.Create(MyDir + "morzal.pfx", "aw", null);
DigitalSignatureUtil.Sign(MyDir + "Document.docx", ArtifactsDir + "File.DetectDigitalSignatures.docx",
    certificateHolder, new SignOptions() { SignTime = DateTime.Now });

// Use a new FileFormatInstance to confirm that it is signed
info = FileFormatUtil.DetectFileFormat(ArtifactsDir + "File.DetectDigitalSignatures.docx");

Assert.True(info.HasDigitalSignature);

// The signatures can then be accessed like this
Assert.AreEqual(1, DigitalSignatureUtil.LoadSignatures(ArtifactsDir + "File.DetectDigitalSignatures.docx").Count);

ExpandedSee Also