Back to Devexpress

How to: Export a Document to HTML Format

wpf-116725-controls-and-libraries-rich-text-editor-examples-files-how-to-export-document-to-html-format.md

latest2.1 KB
Original Source

How to: Export a Document to HTML Format

  • Jun 21, 2023

This example demonstrates how to export the document to the HTML format using the RichEditControl.SaveDocument method.

The RichEditControl instance is passed to the BarItem.ItemClick event handler using the BarItem.Tag property.

View Example

csharp
static void buttonCustomAction_ItemClick_Html(object sender, ItemClickEventArgs e) {
    RichEditControl richEdit = e.Item.Tag as RichEditControl;
    richEdit.LoadDocument("Documents\\Grimm.docx");
    //Export document to the file:
    richEdit.SaveDocument("resultingDocument.html", DocumentFormat.Html);
    //Export document to the stream:
    using (FileStream htmlFileStream = new FileStream("Document_HTML.html", FileMode.Create)) {
        richEdit.SaveDocument(htmlFileStream, DocumentFormat.Html);
    }

    System.Diagnostics.Process.Start("resultingDocument.html");
}
vb
Shared Sub buttonCustomAction_ItemClick_Html(ByVal sender As Object, ByVal e As ItemClickEventArgs)
    Dim richEdit As RichEditControl = TryCast(e.Item.Tag, RichEditControl)
    richEdit.LoadDocument("Documents\Grimm.docx")
    'Export document to the file:
    richEdit.SaveDocument("resultingDocument.html", DocumentFormat.Html)
    'Export document to the stream:
    Using htmlFileStream As New IO.FileStream("Document_HTML.html", IO.FileMode.Create)
        richEdit.SaveDocument(htmlFileStream, DocumentFormat.Html)
    End Using

    System.Diagnostics.Process.Start("resultingDocument.html")
End Sub

See Also

Import an HTML File into the Rich Text Editor or Export a Document to HTML