Skip to main content

Document.HtmlText Property

Gets or sets the document content as HTML text.

Namespace: DevExpress.XtraRichEdit.API.Native

Assembly: DevExpress.RichEdit.v24.1.Core.dll

NuGet Packages: DevExpress.RichEdit.Core, DevExpress.Win.Navigation

Declaration

string HtmlText { get; set; }

Property Value

Type Description
String

A string containing text of the document in HTML format.

Remarks

The HtmlText property returns the HTML document with base64-encoded images embedded in the document body.

The code sample below uses the HtmlText property to export a document to HTML format.

Document document = richEditControl.Document;
document.LoadDocument("FirstLook.docx", DocumentFormat.OpenXml);

// Export to HTML
File.WriteAllText("test.html", document.HtmlText);

// Show the result in a browser window.
System.Diagnostics.Process.Start("test.html");

Use the SubDocument.GetHtmlText method to get the HTML source that contains image references.

Specify a custom IUriProvider to retain the original image URI when a document is loaded and then saved. Refer to the How to: Retain the Image URI in HTML Document article for a code sample.

Use the Document.LoadDocument method to load HTML content.

Use the Document.SaveDocument or RichEditControl.SaveDocumentAs method to save the document in HTML format. The HtmlText method constructs the HTML document with external content - e.g., images - replaced with the name placeholders numbered in consecutive order. That is, images are named img1.img etc.

Handle the BeforeExport event to specify HtmlDocumentExporterOptions and export the HTML document correctly.

Note

If you set the HtmlText property to an HTML string, make sure that the string has the correct encoding.

Check the HTML Tag Support document for a list of supported HTML tags.

See Also