Aspose::Words::FileFormatUtil class

FileFormatUtil class

Provides utility methods for working with file formats, such as detecting file format or converting file extensions to/from file format enums. To learn more, visit the Detect File Format and Check Format Compatibility documentation article.

class FileFormatUtil

Methods

MethodDescription
static ContentTypeToLoadFormat(const System::String &)Converts IANA content type into a load format enumerated value.
static ContentTypeToSaveFormat(const System::String &)Converts IANA content type into a save format enumerated value.
static DetectFileFormat(const System::SharedPtr<System::IO::Stream> &)Detects and returns the information about a format of a document stored in a stream.
static DetectFileFormat(const System::String &)Detects and returns the information about a format of a document stored in a disk file.
static DetectFileFormat(std::basic_istream<CharType, Traits> &)Detects and returns the information about a format of a document stored in a stream.
static ExtensionToSaveFormat(const System::String &)Converts a file name extension into a SaveFormat value.
static ImageTypeToExtension(Aspose::Words::Drawing::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(Aspose::Words::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(Aspose::Words::LoadFormat)Converts a LoadFormat value to a SaveFormat value if possible.
static SaveFormatToExtension(Aspose::Words::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(Aspose::Words::SaveFormat)Converts a SaveFormat value to a LoadFormat value if possible.

Examples

Shows how to detect encoding in an html file.

System::SharedPtr<Aspose::Words::FileFormatInfo> info = FileFormatUtil::DetectFileFormat(get_MyDir() + u"Document.html");

ASSERT_EQ(info->get_LoadFormat(), LoadFormat::Html);

// The Encoding property is used only when we create a FileFormatInfo object for an html document.
// On Windows, the detected ISO-8859-1 encoding is reported as its Windows-1252 superset.
ASSERT_EQ(info->get_Encoding()->get_EncodingName(), isLinux ? System::String(u"Western European (ISO)") : System::String(u"Western European (Windows)"));
ASSERT_EQ(info->get_Encoding()->get_CodePage(), isLinux ? 28591 : 1252);

See Also