HTML5 Web Editor - Programming API

Web.TextControl provides the same interface to the TextParts such as the ServerTextControl. You can iterate through all TextParts including the MainText, TextFrames and HeaderFooter objects. These TextPart objects provide a Selection object that can be used to get and set formatted text and to interact with the content.

A temporary ServerTextControl is used to modify the content of Web.TextControl. The Selection is loaded into a ServerTextControl, modified and loaded back to Web.TextControl.

Demo

The advantage of using a temporary ServerTextControl is the compatibility of existing code written for ServerTextControl. You can reuse all of your existing procedures to modify documents.

Sources

protected void Button1_Click(object sender, EventArgs e)
{
    // insert a new text field into Web.TextControl
    using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
    {
        tx.Create();

        MergeField newField = new MergeField();
        newField.Name = TextBox2.Text;
        newField.Text = "Text Field: " + TextBox2.Text; ;

        tx.ApplicationFields.Add(newField.ApplicationField);

        byte[] data;
        tx.Save(out data, TXTextControl.BinaryStreamType.InternalUnicodeFormat);
        TextControl1.Selection.Load(data, TXTextControl.Web.BinaryStreamType.InternalUnicodeFormat);

        TextBox2.Text = "";
    }
}

HTML5 Web editor