GemBox.Document is a .NET component that enables you to read, write, edit, convert, and print document files from your .NET applications using one simple API.

Word Editor in ASP.NET

HTML can be easily loaded into specific document location with GemBox.Document.

Following example shows how to load HTML text into bookmark.

Visual Studio solution that contains the code can be downloaded from: HtmlEditorSample.zip.

Screenshot
HTML Editor Screenshot

See the full code below.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="HtmlEditorSampleCs.Default" %><%@ Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"><title>HTML Editor Sample</title></head><body><form id="form1" runat="server"><div><CKEditor:CKEditorControl ID="htmlEditor" runat="server"> Hello &lt;b&gt;World!&lt;/b&gt; </CKEditor:CKEditorControl></div><div><asp:Button ID="exportButton" runat="server" Text="Export" OnClick="OnExportButtonClicked" /><asp:Literal Text=" to " runat="server" /><asp:DropDownList ID="outputFormatList" runat="server"><asp:ListItem Value="docx">DOCX</asp:ListItem><asp:ListItem Value="html">HTML</asp:ListItem><asp:ListItem Value="mht">MHTML</asp:ListItem><asp:ListItem Value="rtf">RTF</asp:ListItem><asp:ListItem Value="txt">TXT</asp:ListItem><asp:ListItem Selected="True" Value="pdf">PDF</asp:ListItem><asp:ListItem Value="xps">XPS</asp:ListItem><asp:ListItem Value="png">PNG</asp:ListItem><asp:ListItem Value="jpg">JPEG</asp:ListItem><asp:ListItem Value="gif">GIF</asp:ListItem><asp:ListItem Value="bmp">BMP</asp:ListItem><asp:ListItem Value="tif">TIFF</asp:ListItem><asp:ListItem Value="wdp">WMP</asp:ListItem></asp:DropDownList></div></form></body></html>
using System;
using System.IO;
using GemBox.Document;

namespace HtmlEditorSampleCs
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                ComponentInfo.SetLicense("FREE-LIMITED-KEY");
                ComponentInfo.FreeLimitReached += (s1, e1) => e1.FreeLimitReachedAction = FreeLimitReachedAction.ContinueAsTrial;
            }
        }

        protected void OnExportButtonClicked(object sender, EventArgs e)
        {
            var templatePath = Path.Combine((string)AppDomain.CurrentDomain.GetData("DataDirectory"), "TemplateDocument.docx");

            DocumentModel document;
            using (var stream = File.OpenRead(templatePath))
                document = DocumentModel.Load(stream, LoadOptions.DocxDefault);

            document.Bookmarks["HtmlContent"].GetContent(true).LoadText(this.htmlEditor.Text, LoadOptions.HtmlDefault);

            var fileName = Path.ChangeExtension("Document", this.outputFormatList.SelectedValue);

            document.Save(this.Response, fileName);
        }
    }
}
Imports System.IO
Imports GemBox.Document

Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

        If Not Me.IsPostBack Then
            ComponentInfo.SetLicense("FREE-LIMITED-KEY")
        End If
    End Sub

    Protected Sub OnExportButtonClicked(sender As Object, e As EventArgs)

        Dim templatePath = Path.Combine(DirectCast(AppDomain.CurrentDomain.GetData("DataDirectory"), String), "TemplateDocument.docx")

        Dim document As DocumentModel
        Using stream = File.OpenRead(templatePath)
            document = DocumentModel.Load(stream, LoadOptions.DocxDefault)
        End Using

        document.Bookmarks("HtmlContent").GetContent(True).LoadText(Me.htmlEditor.Text, LoadOptions.HtmlDefault)

        Dim fileName = Path.ChangeExtension("Document", Me.outputFormatList.SelectedValue)

        document.Save(Me.Response, fileName)
    End Sub

End Class

Check next sample.