Skip to main content

.NET (C#) integration

The .NET integration examples are two small ASP.NET applications for .NET Framework 4.8: csharp, built with Web Forms, and csharp-mvc, built with ASP.NET MVC. Both list files, open them in ONLYOFFICE Docs, and save them back through the callback handler. Run either one to see a complete integration working before you write your own. The examples run on Windows only, under IIS.

warning

This example is for testing only. It has no authentication, does not validate link parameters or save requests, and accepts requests from any site, so anyone who can reach it can read and change its files. Do not run it on a public server, and disable it before going to production.

Prerequisites​

When you turn on IIS in Windows Features, open Internet Information Services > World Wide Web Services and select .NET Extensibility 4.8, ASP.NET 4.8, ISAPI Extensions, ISAPI Filters, Default Document, and Request Filtering. In Visual Studio, install the ASP.NET and web development workload.

Step 1. Download the example​

Clone the example repository, go to the example you want to run, and fetch its submodules. The commands below use the Web Forms example. For the MVC example, go to csharp-mvc instead:

git clone --depth 1 https://github.com/ONLYOFFICE/document-server-integration
cd document-server-integration/web/documentserver-example/csharp
git submodule update --init --depth 1 .

Step 2. Configure the connection​

Open the settings.config file (web.appsettings.config in the MVC example) and edit the following keys:

<appSettings>
<add key="files.docservice.url.site" value="http://documentserver/"/>
<add key="storage-path" value=""/>
<add key="files.docservice.secret" value="" />
<add key="files.docservice.url.example" value=""/>
</appSettings>
  • files.docservice.url.site: the address of the server with ONLYOFFICE Docs installed. Replace documentserver with its name or IP address, and keep the trailing slash.
  • storage-path: the folder where the example creates and stores files. If it is empty, the example stores files in its own folder, in a subfolder named after the user's IP address. You can set an absolute path, for example, D:\folder. The IIS application pool identity needs read and write permissions to this folder.
  • files.docservice.secret: must match the JWT settings of ONLYOFFICE Docs. The key is empty by default, which disables JWT in the example. JWT is enabled in ONLYOFFICE Docs by default, so set this key to the secret key of your server.
  • files.docservice.url.example: the address at which ONLYOFFICE Docs reaches the example. Set it if ONLYOFFICE Docs runs on another computer or in Docker, where the address you open in the browser, such as localhost, points somewhere else.

If you want to experiment with the editor configuration, modify the parameters in the DocEditor.aspx.cs file (Models/FileModel.cs in the MVC example).

Step 3. Build and run the example​

  1. Open OnlineEditorsExample.sln (OnlineEditorsExampleMVC.sln in the MVC example) in Visual Studio and select Build > Build Solution. Visual Studio restores the NuGet packages and compiles the example into the bin folder.
  2. In IIS Manager, right-click Sites and select Add Website. Set Physical path to the example folder and Port to any free port.
  3. In Application Pools, make sure that the pool of the new site uses .NET CLR version v4.0.
  4. Right-click the site and select Manage Website > Browse.

The browser opens http://localhost:<port>/. You will see the example's start page, where you can upload a file or create a new document, spreadsheet, presentation, or PDF form.

Troubleshooting​

  • The document security token is not correctly formed: JWT is disabled in the example (files.docservice.secret is empty), or files.docservice.secret does not match the secret of ONLYOFFICE Docs.
  • Download failed: ONLYOFFICE Docs cannot reach the example. Set files.docservice.url.example in settings.config (web.appsettings.config in the MVC example) to an address that ONLYOFFICE Docs can resolve.