Log In
[Expand]General Information
[Collapse]WinForms Controls
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Map Control
  [Collapse]Rich Text Editor
   [Expand]Getting Started
   [Expand]Visual Elements
    [Expand]Text Boxes
    [Expand]Search and Replace
    [Expand]Mail Merge
    [Expand]Spell Check
      How to: Save Selected Image to a File
      How to: Determine Formatting Capabilities Required to Export the Document
      How to: Reduce the File Size When Saving a Document Containing Pictures
      How to: Retain the Image URI in HTML Document
      How To: Export Document to PDF format
      How To: Export Document to HTML format
    [Expand]User Interface Customization
   [Expand]Member Tables
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Report Server
[Expand]eXpressApp Framework
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

How to: Retain the Image URI in HTML Document

When an HTML document is loaded, it is imported and transformed into a native RichEdit representation. When you save it, you are actually exporting a loaded document from the native format to the format of the resulting document. If you are saving a document as HTML, you have to choose HTML representation for images. XtraRichEdit properties and methods deals with this problem differently as you can see from the description that follows.

The RichEditControl.HtmlText property always returns an HTML source containing embedded images base64-encoded.

When you are saving a document via RichEditControl.SaveDocument or RichEditControl.SaveDocumentAs methods, or the SaveDocumentAsCommand command, the image representation is dependent on the HtmlExportOptionsBase.EmbedImagesInHTML setting. By default, this setting is set to false and images are named with the "image" word followed by its sequential number in a file. Images are saved to the folder with the name that is the combination of the file name, underscore and the "files" word. That is, the first gif image in the Test.html file is saved to the Test_files\image0.gif location.

You can implement a custom UriProvider to specify location for each document image when the document is saved to an HTML format. To accomplish this, create a IUriProvider descendant and register it in RichEditControl services.

You can even specify a custom UriProvider for each call to the SubDocument.GetHtmlText method to obtain a different HTML, if required.

Each image in RichEditControl has the OfficeImage.Uri property with a value that is equal to the original URI of an image when it is imported to the control.

To retain an original image URI in a saved HTML document, we should implement a custom UriProvider providing original image URI, as illustrated in the code below.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E3189.

How would you rate this topic?​​​​​​​