Skip to main content

OnlyOffice

OnlyOffice hosts the ONLYOFFICE document editor in a Wisej.NET page. ONLYOFFICE edits Word, Excel and PowerPoint documents in the browser, with an interface close to desktop Office. The control is named Editor, in the Wisej.Web.Ext.OnlyOffice namespace.

Preview: not ready for production

This extension is a preliminary implementation. In the 4.1 source, the control loads the ONLYOFFICE script and creates an editor, but the editor configuration is fixed in the embedded client script. It always opens Documents/Features Table.docx, and nothing you set on the server reaches it: not the document, not the user, not a save callback. To use it in an application, you have to change that script (see Adapting the control). If you only need to display Office documents, use OfficeViewer.

Requirements​

ONLYOFFICE isn't a JavaScript library you can embed on its own. The editor runs against an ONLYOFFICE Document Server, which converts, renders and co-edits the documents:

  • A Document Server. Install the free Community Edition yourself, e.g. with Docker, or use a commercial edition or ONLYOFFICE's cloud. The browser loads the editor script, api.js, from that server.
  • Documents the Document Server can download. The Document Server fetches each document from its url server-side, so the URL must be absolute and reachable from the Document Server, not just from the user's browser.
  • A callback URL for saving. When users edit, the Document Server posts the changed document to a callbackUrl in your application, which must store it. See ONLYOFFICE's callback handler documentation.
  • JWT signing, which recent Document Server versions enable by default. The editor configuration must be signed with the server's secret. See Signature.
Licensing

ONLYOFFICE Docs Community Edition is open source under the AGPL v3. It limits the number of simultaneous connections, and the AGPL has obligations of its own. Commercial editions remove the limits. Check ONLYOFFICE's editions before you deploy.

Installation​

The 4.1 source has no NuGet package for OnlyOffice. Build the Wisej.Web.Ext.OnlyOffice project from the source repository and reference it, or add the project to your solution. It targets .NET Framework 4.8 and .NET 8 or later, including the -windows, Android, iOS and Mac Catalyst targets.

Getting started​

Add an Editor to a page and point OnlyOfficeURL at the api.js of your Document Server:

var editor = new Wisej.Web.Ext.OnlyOffice.Editor
{
Dock = DockStyle.Fill,
OnlyOfficeURL = "https://docs.example.com/web-apps/apps/api/documents/api.js"
};
this.Controls.Add(editor);
PropertyDefaultWhat it does
OnlyOfficeURLhttps://doc.onlyoffice.com/OfficeWeb/apps/api/documents/api.jsThe URL of the Document Server's api.js. null or "" restores the default.
Set OnlyOfficeURL before the editor is shown

The script URL is read the first time the control builds its list of Packages. Changing OnlyOfficeURL after that doesn't change the script the browser loads. Set it in the designer or the constructor.

Adapting the control​

The editor is created by JavaScript/startup.js in the extension project. Today it calls new DocsAPI.DocEditor(id, config) with a hard-coded config. To make the control usable, pass the configuration from the server instead:

  1. Add server properties for what changes per document: the document URL, file type, title and key, the user, the callback URL, and the JWT token.
  2. Serialize them into the init script, the way other Wisej.NET widgets replace an $options placeholder. The script already has a commented-out var options = $options; line for that.
  3. Build the ONLYOFFICE configuration object from those options, sign it on the server, and handle the save callback in your application.

The ONLYOFFICE basic concepts guide explains how the browser, the Document Server and your application interact.

note

The Editor control implements IWisejHandler, so it could serve documents and receive the save callback through its own service URL. That part isn't implemented yet: its request handler is empty.

API reference​