Overview
This guide will walk you through creating a basic page that allows users to upload, edit, and download documents using the OnlyOffice Control.
Basic Implementation
Register the Control
First, register the OnlyOffice Control on your ASPX page: <%@ Page Language="C#"
AutoEventWireup="true"
CodeBehind="Default.aspx.cs"
Inherits="YourNamespace._Default"
ValidateRequest="false" %>
<%@ Register Src="~/Controls/OnlyOfficeEditor/OnlyOfficeEditor.ascx"
TagPrefix="oo"
TagName="Editor" %>
Set ValidateRequest="false" on pages using the OnlyOffice Control to prevent request validation issues with document content.
Add Control to Page
Add the editor control to your page markup: <!DOCTYPE html>
<html>
<head runat="server">
<title>Document Editor</title>
<style>
iframe {
height: 700px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>OnlyOffice Document Editor</h1>
<!-- File Upload Section -->
<div>
<asp:FileUpload ID="fuFile" runat="server" />
<asp:Button ID="btnUpload"
runat="server"
Text="Upload and Open"
OnClick="btnUpload_Click" />
<asp:Literal ID="litStatus" runat="server" />
</div>
<!-- OnlyOffice Editor -->
<oo:Editor ID="docEditor"
runat="server"
CaptureTriggerId="btnDownload" />
<!-- Download Button -->
<div>
<asp:Button ID="btnDownload"
runat="server"
Text="Download Document"
OnClick="btnDownload_Click" />
</div>
</div>
</form>
</body>
</html>
Understanding CaptureTriggerId
The CaptureTriggerId property specifies which button(s) should trigger document capture from the editor. When clicked, the control automatically:
Requests the current document from the OnlyOffice editor
Stores it as base64 in a hidden field
Triggers a postback
You can specify multiple buttons separated by commas: CaptureTriggerId="btnSave,btnDownload,btnConvert"
Implement Upload Handler
In your code-behind file, implement the upload functionality: using System ;
using System . IO ;
using System . Web . UI ;
namespace YourNamespace
{
public partial class _Default : Page
{
protected void Page_Load ( object sender , EventArgs e )
{
if ( ! IsPostBack )
{
// Optional: Load a default document
string sampleFilePath = Server . MapPath ( "~/Documents/sample.docx" );
if ( File . Exists ( sampleFilePath ))
{
docEditor . SetDocumentFromFile ( sampleFilePath , "sample.docx" );
}
}
}
protected void btnUpload_Click ( object sender , EventArgs e )
{
if ( ! fuFile . HasFile )
{
litStatus . Text = "<span style='color:red;'>Please select a file</span>" ;
return ;
}
// Load the uploaded file into the editor
docEditor . SetDocumentFromBytes ( fuFile . FileBytes , fuFile . FileName );
// Set editor mode (optional)
docEditor . Mode = "edit" ; // or "view" for read-only
litStatus . Text = "<span style='color:green;'>Document loaded successfully</span>" ;
}
}
}
Implement Download Handler
Add functionality to download the edited document: protected void btnDownload_Click ( object sender , EventArgs e )
{
// Get the edited document bytes
byte [] documentBytes = docEditor . GetEditedDocumentBytes ();
if ( documentBytes == null || documentBytes . Length == 0 )
{
litStatus . Text = "<span style='color:red;'>No edited document available</span>" ;
return ;
}
// Clear the cached document
docEditor . ClearEditedDocument ();
// Prepare file for download
var fileName = docEditor . DocumentName ?? "document.docx" ;
Response . Clear ();
Response . ContentType = "application/octet-stream" ;
Response . AddHeader ( "Content-Disposition" , "attachment; filename=" + fileName );
Response . AddHeader ( "Content-Length" , documentBytes . Length . ToString ());
Response . BinaryWrite ( documentBytes );
Response . End ();
}
The CaptureTriggerId property automatically captures the document when the download button is clicked, so you don’t need to manually call capture methods.
Configuring Editor Properties
You can configure various properties of the OnlyOffice editor:
Basic Configuration
protected void Page_Load ( object sender , EventArgs e )
{
if ( ! IsPostBack )
{
// Configure editor properties
docEditor . Mode = "edit" ; // "edit" or "view"
docEditor . Lang = "en" ; // Language: "en", "es", "fr", etc.
docEditor . EditorHeight = "600px" ; // Editor height
docEditor . UserId = "123" ; // Current user ID
docEditor . UserDisplayName = "John Doe" ; // Current user name
// Load a document
LoadDocument ();
}
}
Loading Documents
There are three ways to load documents into the editor:
From Bytes
From File
From Upload ID
// Load from byte array (e.g., from upload)
byte [] fileBytes = fuFile . FileBytes ;
string fileName = fuFile . FileName ;
docEditor . SetDocumentFromBytes ( fileBytes , fileName );
Advanced Features
PDF Conversion
Convert the current document to PDF:
protected void btnConvertToPdf_Click ( object sender , EventArgs e )
{
try
{
// Convert the current document to PDF bytes
byte [] pdfBytes = docEditor . ConvertCurrentDocumentToPdfBytes ();
// Download the PDF
Response . Clear ();
Response . ContentType = "application/pdf" ;
Response . AddHeader ( "Content-Disposition" ,
"attachment; filename=" + Path . GetFileNameWithoutExtension ( docEditor . DocumentName ) + ".pdf" );
Response . BinaryWrite ( pdfBytes );
Response . End ();
}
catch ( Exception ex )
{
litStatus . Text = "<span style='color:red;'>Error converting to PDF: " + ex . Message + "</span>" ;
}
}
PDF conversion requires the OnlyOffice Document Server conversion service to be available.
View-Only Mode
Set the editor to read-only mode:
protected void btnViewOnly_Click ( object sender , EventArgs e )
{
// Switch to view mode
docEditor . Mode = "view" ;
// Reload the page to apply the change
Response . Redirect ( Request . Url . ToString ());
}
Checking Document Status
Check if a document is loaded or edited:
protected void Page_Load ( object sender , EventArgs e )
{
// Check if a document is currently loaded
if ( docEditor . HasDocument )
{
lblDocumentName . Text = docEditor . DocumentName ;
}
// Check if there's an edited version
if ( docEditor . HasEditedDocument )
{
btnDownload . Enabled = true ;
btnDownload . Text = "Download Edited Document" ;
}
}
Complete Example
Here’s a complete working example:
Default.aspx
Default.aspx.cs
<%@ Page Language="C#"
AutoEventWireup="true"
CodeBehind="Default.aspx.cs"
Inherits="OnlyOfficeControl._Default"
ValidateRequest="false" %>
<%@ Register Src="~/Controls/OnlyOfficeEditor/OnlyOfficeEditor.ascx"
TagPrefix="oo"
TagName="Editor" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title>Document Editor</title>
<style>
iframe { height: 700px; }
.toolbar { padding: 20px; background: #f5f5f5; margin-bottom: 20px; }
.editor-container { padding: 20px; }
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="toolbar">
<asp:FileUpload ID="fuFile" runat="server" />
<asp:Button ID="btnUpload"
runat="server"
Text="Upload and Open"
OnClick="btnUpload_Click" />
<asp:Literal ID="litStatus" runat="server" />
</div>
<div class="editor-container">
<oo:Editor ID="docEditor"
runat="server"
CaptureTriggerId="btnDownload" />
<div style="margin-top: 20px;">
<asp:Button ID="btnDownload"
runat="server"
Text="Save and Download"
OnClick="btnDownload_Click" />
</div>
</div>
</form>
</body>
</html>
Common Patterns
Upload, Edit, and Save Workflow
// 1. User uploads document
protected void btnUpload_Click ( object sender , EventArgs e )
{
docEditor . SetDocumentFromBytes ( fuFile . FileBytes , fuFile . FileName );
docEditor . Mode = "edit" ;
}
// 2. User edits in OnlyOffice
// (happens in browser)
// 3. User saves document
protected void btnSave_Click ( object sender , EventArgs e )
{
byte [] editedBytes = docEditor . GetEditedDocumentBytes ();
// Save to database, file system, etc.
SaveToDatabase ( editedBytes , docEditor . DocumentName );
docEditor . ClearEditedDocument ();
}
Load from Database
protected void LoadDocumentFromDatabase ( int documentId )
{
// Retrieve document from database
var doc = GetDocumentFromDatabase ( documentId );
// Load into editor
docEditor . SetDocumentFromBytes ( doc . Content , doc . FileName );
docEditor . Mode = "edit" ;
docEditor . UserId = CurrentUser . Id . ToString ();
docEditor . UserDisplayName = CurrentUser . FullName ;
}
Troubleshooting
Editor doesn't show document
Verify that:
A document was loaded using one of the SetDocument* methods
The HasDocument property returns true
No JavaScript errors in the browser console
Download returns empty document
Ensure:
The button is listed in CaptureTriggerId
The document was actually edited (check HasEditedDocument)
The callback URL is reachable from OnlyOffice server
Check:
OnlyOffice conversion service is running
The document format is supported for conversion
Network connectivity between your server and OnlyOffice
Next Steps
Now that you have a basic implementation working, explore:
Customizing the editor appearance with CSS
Implementing user permissions and access control
Integrating with your document management system
Adding collaboration features
Implementing version control
API Reference Explore the complete API documentation