Setup Doconut in .NET Framework 4.7

Web.config file

The viewer requires HttpHandler to be registered via web.config file. Depending on your IIS version it can be done using the following section defined in web.config (also shown in our sample Asp.Net project’s web.config file)

Below IIS 7

  <add verb="GET,POST" path="DocImage.axd" type="Doconut.DocImageHandler, Doconut" />
For Webfarm, use this configuration
  <add verb="GET,POST" path="DocImage.axd" type="Doconut.DiskImageHandler, Doconut" />

IIS 7 and above

  <add name="DocImage" verb="GET,POST" path="DocImage.axd" type="Doconut.DocImageHandler, Doconut" />
For Webfarm, use this configuration
  <add name="DocImage" verb="GET,POST" path="DocImage.axd" type="Doconut.DiskImageHandler, Doconut" />

Register in ASPX pages

This line registers the "Doconut" assembly with the specified namespace and tag prefix, enabling you to utilize Doconut controls and functionalities within your ASP.NET application.

<%@ Register Assembly="Doconut" Namespace="Doconut" TagPrefix="asp" %>

Add Viewer control in the ASPX page

Include the following line of code to add the viewer control into your project.

<asp:Viewer ID="ctlDoc" runat="server"/>

Add Doconut Namespaces

In your project, add the following usings:

using Doconut;
using Doconut.Configs;
using Doconut.Formats;
using Doconut.Clouds;

Instantiate Viewer object

This line instantiates a new instance of the Viewer class, allowing you to create a viewer object within your code.

var viewer = new Viewer { ID = "ctlDoc", BasePath = "/" }

Setup a config object

Per example, this line initializes a new PdfConfig object named "config" with specific configurations for handling PDF documents.

var config = new PdfConfig { DefaultRender = true, ExtractHyperlinks = true };

Open your document

This line invokes the "OpenDocument" method of the viewer object, passing the path of the document file located on the server and the previously configured PdfConfig object as parameters.

var token = viewer.OpenDocument(filename, config);

Add Licenses to Your Project

Automatic License Detection

Doconut can automatically detect licenses if they are placed within the project's bin folder.

Add Manual Default License

If you prefer to add the license manually, the following options are available:

Add License by File Path

This method uses the Viewer.DoconutLicense(string licencePath) overload to add a license by specifying the path to the license file.

var licensePath = "path/to/your/license.lic";

Add License by Stream

This method uses the Viewer.DoconutLicense(Stream licenseStream) overload to add a license using a stream.

using (var licenseStream = new FileStream("path/to/your/license", FileMode.Open))

Add License by XML Document

This method uses the Viewer.DoconutLicense(XMLDocument licence) overload to add a license using an XML document.

var xmlDoc = new XmlDocument();

Add Plugin License by File Path

This method uses the Viewer.SetLicensePlugin(string pathPluginLicence) overload to add a plugin license by specifying the path to the plugin license file.

var pluginLicensePath = "path/to/your/plugin-license.lic";

Add Plugin License by Stream

This method uses the Viewer.SetLicensePlugin(Stream pluginLicence) overload to add a plugin license using a stream.

using (var pluginLicenseStream = new FileStream("path/to/your/plugin-license.lic", FileMode.Open))

Add Plugin License by XML Document

This method uses the Viewer.SetLicensePlugin(XMLDocument xmlPluginLicence) overload to add a plugin license using an XML document.

var pluginXmlDoc = new XmlDocument();

Configuration for web.config

The following configuration entries are necessary for the web.config file to ensure compatibility with Doconut and the .NET Framework. These settings manage assembly binding redirects to use the specified versions of various assemblies, which is crucial for avoiding conflicts and ensuring that the correct versions of dependencies are loaded.

  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
    <bindingRedirect oldVersion="" newVersion="" />
    <assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
    <bindingRedirect oldVersion="" newVersion="" />
    <assemblyIdentity name="System.Text.Encoding.CodePages" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="" newVersion="" />
    <assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
    <bindingRedirect oldVersion="" newVersion="" />
    <assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
    <bindingRedirect oldVersion="" newVersion="" />
    <assemblyIdentity name="System.Drawing.Common" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
    <bindingRedirect oldVersion="" newVersion="" />
    <assemblyIdentity name="MessagePack" publicKeyToken="9c7f9b36b37eaddf" culture="neutral" />
    <bindingRedirect oldVersion="" newVersion="" />
    <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
    <bindingRedirect oldVersion="" newVersion="" />
    <assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="" newVersion="" />

Required NuGet Packages

To ensure your project is fully compatible with Doconut and the .NET Framework, the following NuGet packages need to be included. These packages provide the necessary libraries and tools required for the application's functionality:

  • MessagePack - Version 2.5.140
  • MessagePack.Annotations - Version 2.5.140
  • Microsoft.Bcl.AsyncInterfaces - Version 8.0.0
  • Microsoft.NET.StringTools - Version 17.6.3
  • System.Collections.Immutable - Version 6.0.0
  • System.Drawing.Common - Version 6.0.0
  • System.Memory - Version 4.5.5
  • System.Reflection.Emit - Version 4.7.0
  • System.Reflection.Emit.Lightweight - Version 4.7.0
  • System.Security.Cryptography.Pkcs - Version 8.0.0
  • System.Text.Encoding.CodePages - Version 8.0.0
  • System.Text.Encodings.Web - Version 8.0.0
  • System.Text.Json - Version 8.0.3

Render Configuration Options

You can configure the rendering behavior using the following options:

  • CadConfig: Used for DWG, DXF, and DGN files.
  • EmailConfig: Used for EML, EMLX, and MSG files.
  • EpubConfig: Used for EPUB files.
  • ExcelConfig: Used for Excel and CSV files.
  • MhtConfig: Used for MHT files.
  • PptConfig: Used for PowerPoint files.
  • ProjectConfig: Used for MPP files.
  • PsdConfig: Used for PSD files.
  • TxtConfig: Used for TXT files.
  • TiffConfig: Used for TIFF files.

The render options are configured using the DefaultRender property:

  • DefaultRender = true : This option offers higher quality rendering but uses more server memory and processing time.
  • DefaultRender = false : This option provides faster rendering at the expense of slightly reduced quality. It optimizes processing time and memory usage.

Example usage:

var config = new CadConfig { DefaultRender = false }; // or true

Update Regarding AjaxControlToolkit in NuGet Package

We have made changes to our NuGet package to improve compatibility and avoid conflicts with existing versions of AjaxControlToolkit. Moving forward, the AjaxControlToolkit will no longer be included in our NuGet package due to versioning issues reported by users. Instead, users are advised to manually install AjaxControlToolkit version 4.1.50508 into their projects.

To ensure smooth integration and avoid version conflicts:

  • Manually Install AjaxControlToolkit: Please install AjaxControlToolkit version 4.1.50508 manually into your project.

This adjustment aims to provide better control over dependencies and ensure compatibility with various project configurations.