FileFormatUtil

FileFormatUtil class

Provides utility methods for working with file formats, such as detecting file format or converting file extensions to/from file format enums.

public static class FileFormatUtil

Methods

Name Description
static ContentTypeToLoadFormat(string) Converts IANA content type into a load format enumerated value.
static ContentTypeToSaveFormat(string) Converts IANA content type into a save format enumerated value.
static DetectFileFormat(Stream) Detects and returns the information about a format of a document stored in a stream.
static DetectFileFormat(string) Detects and returns the information about a format of a document stored in a disk file.
static ExtensionToSaveFormat(string) Converts a file name extension into a SaveFormat value.
static ImageTypeToExtension(ImageType) Converts an Aspose.Words image type enumerated value into a file extension. The returned extension is a lower-case string with a leading dot.
static LoadFormatToExtension(LoadFormat) Converts a load format enumerated value into a file extension. The returned extension is a lower-case string with a leading dot.
static LoadFormatToSaveFormat(LoadFormat) Converts a LoadFormat value to a SaveFormat value if possible.
static SaveFormatToExtension(SaveFormat) Converts a save format enumerated value into a file extension. The returned extension is a lower-case string with a leading dot.
static SaveFormatToLoadFormat(SaveFormat) Converts a SaveFormat value to a LoadFormat value if possible.

Examples

Shows how to detect encoding in an html file.

FileFormatInfo info = FileFormatUtil.DetectFileFormat(MyDir + "Document.html");

Assert.AreEqual(LoadFormat.Html, info.LoadFormat);

// The Encoding property is used only when we create a FileFormatInfo object for an html document.
Assert.AreEqual("Western European (Windows)", info.Encoding.EncodingName);
Assert.AreEqual(1252, info.Encoding.CodePage);

See Also