Load from URL

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 →

The following code snippet shows how to load a document from a URL:

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

string url = "https://github.com/groupdocs-viewer/GroupDocs.Viewer-for-.NET/blob/master/Examples/GroupDocs.Viewer.Examples.CSharp/Resources/SampleFiles/sample.docx?raw=true";

Stream stream = DownloadFile(url);

using (Viewer viewer = new Viewer(stream, new LoadOptions(FileType.DOCX)))
{
    HtmlViewOptions viewOptions = HtmlViewOptions.ForEmbeddedResources();
    viewer.View(viewOptions);
}

static Stream DownloadFile(string url)
{
    WebRequest request = WebRequest.Create(url);
    using (WebResponse response = request.GetResponse())
        return GetFileStream(response);
}

static Stream GetFileStream(WebResponse response)
{
    MemoryStream fileStream = new MemoryStream();
    using (Stream responseStream = response.GetResponseStream())
        responseStream.CopyTo(fileStream);
    fileStream.Position = 0;
    return fileStream;
}
Imports System.IO
Imports System.Net
Imports GroupDocs.Viewer
Imports GroupDocs.Viewer.Options
' ...

Module Program
    Sub Main(args As String())

        Dim url As String = "https://github.com/groupdocs-viewer/GroupDocs.Viewer-for-.NET/blob/master/Examples/GroupDocs.Viewer.Examples.CSharp/Resources/SampleFiles/sample.docx?raw=true"

        Dim stream As Stream = DownloadFile(url)

        Using viewer As New Viewer(stream, new LoadOptions(FileType.DOCX))
            Dim viewOptions As HtmlViewOptions = HtmlViewOptions.ForEmbeddedResources()
            viewer.View(viewOptions)
        End Using
    End Sub

    Private Function DownloadFile(ByVal url As String) As Stream
        Dim request As WebRequest = WebRequest.Create(url)
        Using response As WebResponse = request.GetResponse()
            Return GetFileStream(response)
        End Using
    End Function

    Private Function GetFileStream(ByVal response As WebResponse) As Stream
        Dim fileStream As New MemoryStream()
        Using responseStream As Stream = response.GetResponseStream()
            responseStream.CopyTo(fileStream)
        End Using
        fileStream.Position = 0
        Return fileStream
    End Function
End Module
p_1.html (317 KB)
p_2.html (149 KB)
p_3.html (1238 KB)

Download full output