Example E3123
Visible to All Users

How to: Import HTML Files that Contain Images Referenced with a Custom Prefix

This example illustrates how to obtain an image referenced with the 'cid' prefix from an external file in BMP format.

The Rich Text Editor allows you to import HTML files that contain embedded images or links to external images with the src attribute specified as an image URL. However, you can have web files where images are referenced in a custom manner (for example, with the prefix 'cid' in the img src attribute, as in email files). In this case, you need to implement and register a custom IUriStreamProvider to import these files into the Rich Text Editor.

Files to Review

More Examples

Documentation

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

Program.cs(vb)
C#
using DevExpress.Office.Services; using DevExpress.Security; using DevExpress.XtraRichEdit; using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Windows.Forms; namespace RichIUriStreamProviderExample { static class Program { /// <summary> /// The main entry point for the application. /// </summary> private static string basePath = Directory.GetCurrentDirectory() + @"\TestDocs\"; static void Main(string[] args) { using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer()) { // Custom IUriStreamProvider registration IUriStreamService uriStreamService = wordProcessor.GetService<IUriStreamService>(); uriStreamService.RegisterProvider(new CustomUriStreamProvider(basePath, "bmp")); wordProcessor.LoadDocument(basePath + "test.html"); wordProcessor.SaveDocument("Result.docx", DocumentFormat.OpenXml); } //Open the result var p = new Process(); p.StartInfo = new ProcessStartInfo(@"Result.docx") { UseShellExecute = true }; p.Start(); } } public class CustomUriStreamProvider : IUriStreamProvider { private string basePath; private string imageExtension; public string BasePath { get { return basePath; } set { basePath = value; } } public string ImageExtension { get { return imageExtension; } set { imageExtension = value; } } public CustomUriStreamProvider(string basePath, string imageExtension) { BasePath = basePath; ImageExtension = imageExtension; } public Stream GetStream(string url) { string fileName = string.Format("{0}.{1}", url.Replace("cid:", string.Empty), ImageExtension); MemoryStream memoryStream = new MemoryStream(); using (Image image = Image.FromFile(BasePath + fileName)) image.Save(memoryStream, ImageFormat.Bmp); memoryStream.Seek(0, SeekOrigin.Begin); return memoryStream; } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.