This example demonstrates how to set up a basic OnlyOffice document editor with file upload functionality. Users can upload a document and edit it directly in the browser.
using System;using System.IO;using System.Web.UI;namespace OnlyOfficeControl{ public partial class _Default : Page { protected void Page_Load(object sender, EventArgs e) { // Optionally load a default document on first visit if (!IsPostBack) { string sampleFilePath = Server.MapPath("~/doc.docx"); if (File.Exists(sampleFilePath)) { byte[] fileBytes = File.ReadAllBytes(sampleFilePath); docEditor.SetDocumentFromBytes(fileBytes, "doc.docx"); } } } protected void btnUpload_Click(object sender, EventArgs e) { if (!fuFile.HasFile) { litStatus.Text = "<span class='text-warning'>Please select a file.</span>"; return; } // Load the uploaded document into the editor docEditor.SetDocumentFromBytes(fuFile.FileBytes, fuFile.FileName); litStatus.Text = "<span class='text-success'>Document loaded successfully!</span>"; } }}
4
Configure the Editor Control
Set the OnlyOffice server URL and JWT secret in your control:
OnlyOfficeEditor.ascx.cs
public partial class OnlyOfficeEditor : UserControl{ // URL of the OnlyOffice Document Server API public string OnlyOfficeApiUrl { get; set; } = "https://your-server.com/web-apps/apps/api/documents/api.js"; // JWT secret key (must match your OnlyOffice server configuration) public string JwtSecret { get; set; } = "your_secret_key"; // Public base URL for callbacks public string PublicBaseUrl { get; set; } = "https://your-app.com"; // Editor mode: "edit" or "view" public string Mode { get; set; } = "edit"; // Editor language public string Lang { get; set; } = "en";}