Specify file type for comparison manually

GroupDocs.Comparison lets you specify the document file type explicitly via LoadOptions.FileType instead of relying on automatic format detection.

Why specify the file type

When no file type is provided, GroupDocs.Comparison inspects the file’s contents to determine its format. This detection is reliable but adds processing time, which can be noticeable for large files.

If you already know the format — for example, because the input is constrained by your application — passing it explicitly skips detection and lets the library go straight to loading. For high-throughput pipelines or batch jobs over large documents, this can produce a measurable speedup.

Specify the file type explicitly

Use this approach when the document format is known at compile time.

using GroupDocs.Comparison;
using GroupDocs.Comparison.Options;
// ...

LoadOptions loadOptions = new LoadOptions
{
    FileType = FileType.DOCX
};

using (Comparer comparer = new Comparer("source.docx", loadOptions))
{
    comparer.Add("target.docx", loadOptions);
    comparer.Compare("result.docx");
}

Derive the file type from a file path

When the file path is available and its extension is reliable, use FileType.FromFileNameOrExtension to resolve the FileType from the extension. This still skips content-based auto-detection, but keeps the calling code generic.

using GroupDocs.Comparison;
using GroupDocs.Comparison.Options;
using GroupDocs.Comparison.Result;
// ...

string sourcePath = "source.docx";
string targetPath = "target.docx";

LoadOptions sourceLoadOptions = new LoadOptions
{
    FileType = FileType.FromFileNameOrExtension(sourcePath)
};

LoadOptions targetLoadOptions = new LoadOptions
{
    FileType = FileType.FromFileNameOrExtension(targetPath)
};

using (Comparer comparer = new Comparer(sourcePath, sourceLoadOptions))
{
    comparer.Add(targetPath, targetLoadOptions);
    comparer.Compare("result.docx");
}

See also

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.