FileFormatUtil Class
Provides utility methods for working with file formats, such as detecting file format or converting file extensions to/from file format enums.
Inheritance Hierarchy
SystemObject
  Aspose.WordsFileFormatUtil

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.9
Syntax
public static class FileFormatUtil

The FileFormatUtil type exposes the following members.

Methods
  NameDescription
Public methodStatic memberCode exampleContentTypeToLoadFormat
Converts IANA content type into a load format enumerated value.
Public methodStatic memberCode exampleContentTypeToSaveFormat
Converts IANA content type into a save format enumerated value.
Public methodStatic memberCode exampleDetectFileFormat(Stream)
Detects and returns the information about a format of a document stored in a stream.
Public methodStatic memberCode exampleDetectFileFormat(String)
Detects and returns the information about a format of a document stored in a disk file.
Public methodStatic memberCode exampleExtensionToSaveFormat
Converts a file name extension into a SaveFormat value.
Public methodStatic memberCode exampleImageTypeToExtension
Converts an Aspose.Words image type enumerated value into a file extension. The returned extension is a lower-case string with a leading dot.
Public methodStatic memberCode exampleLoadFormatToExtension
Converts a load format enumerated value into a file extension. The returned extension is a lower-case string with a leading dot.
Public methodStatic memberCode exampleLoadFormatToSaveFormat
Converts a LoadFormat value to a SaveFormat value if possible.
Public methodStatic memberCode exampleSaveFormatToExtension
Converts a save format enumerated value into a file extension. The returned extension is a lower-case string with a leading dot.
Public methodStatic memberCode exampleSaveFormatToLoadFormat
Converts a SaveFormat value to a LoadFormat value if possible.
Examples
Shows how to detect encoding in an html file.
[C#]

// 'DetectFileFormat' not working on a non-html files
FileFormatInfo info = FileFormatUtil.DetectFileFormat(MyDir + "Document.doc");
Assert.AreEqual(LoadFormat.Doc, info.LoadFormat);
Assert.IsNull(info.Encoding);

// This time the property will not be null
info = FileFormatUtil.DetectFileFormat(MyDir + "Document.LoadFormat.html");
Assert.AreEqual(LoadFormat.Html, info.LoadFormat);
Assert.IsNotNull(info.Encoding);

// It now has some more useful information
Assert.AreEqual("iso-8859-1", info.Encoding.BodyName);
See Also