Specify file type when loading a document

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Viewer MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-viewer -- dnx GroupDocs.Viewer.Mcp --yes
Folders, licensing and more →

When loading a document by specifying a path to a file or using FileStream, GroupDocs.Viewer determines file type by extension. Otherwise, GroupDocs.Viewer tries to determine file type by its signature or content. It takes time and may affect performance.

You can specify the file type using LoadOptions. If you do this, GroupDocs.Viewer skips file type detection and use the specified type.

The following code snippet shows how to specify the file type when loading a document:

using System.IO;
using GroupDocs.Viewer;
using GroupDocs.Viewer.Options;
// ...

Stream stream = GetFileStream("sample.docx"); //TODO: implement your method

// Specify the file type.
LoadOptions loadOptions = new LoadOptions(FileType.DOCX);

//Render a file.
using (Viewer viewer = new Viewer(stream, loadOptions))
{
    HtmlViewOptions viewOptions = HtmlViewOptions.ForEmbeddedResources();
    viewer.View(viewOptions);
}
Imports System.IO
Imports GroupDocs.Viewer
Imports GroupDocs.Viewer.Options
' ...

Module Program
    Sub Main(args As String())
        Dim stream As Stream = GetFileStream("sample.docx") 'TODO: implement your method
    
        ' Specify the file type.
        Dim loadOptions As LoadOptions = New LoadOptions(FileType.DOCX)
    
        'Render a file.
        Using viewer As Viewer = New Viewer(stream, loadOptions)
            Dim viewOptions As HtmlViewOptions = HtmlViewOptions.ForEmbeddedResources()
            viewer.View(viewOptions)
        End Using
    End Sub
End Module