.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
A newer version of this page is available.

IUriProvider Interface

Obsolete. Defines the provider of the locations for external objects in document export.

Namespace: DevExpress.XtraRichEdit.Services

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


[Obsolete("Please use the DevExpress.Office.Services.IUriProvider instead", true)]
public interface IUriProvider :


When the document is exported to a format that implies that a part of the document’s content is located externally, such as HTML format, the IUriProvider interface provides Uniform Resource Locators (URI) for the external objects. The IUriProvider.CreateCssUri method processes the style information , and the IUriProvider.CreateImageUri processes images.

An object implementing the IUriProvider interface is specified as the parameter for the SubDocument.GetHtmlText method.

The following code snippet illustrates how to add a custom IUriProvider class instance to services, and implement its functionality to save CSS files and provide unique names for image files.

This example demonstrates how to use the DocumentImage.Uri property to set the image’s src attribute when a document is saved in HTML format. You can switch on the HtmlDocumentExporterOptions.EmbedImages option to observe that the custom URI provider is idle for embedded images.


The complete sample project How to retain the original image URI in an HTML document is available in the DevExpress Examples repository.

using DevExpress.Office.Services;
using DevExpress.XtraRichEdit.API.Native;
using DevExpress.XtraRichEdit.Export;
using System;
// ...
        private void richEditControl1_DocumentLoaded(object sender, EventArgs e)
            IUriProviderService service = richEditControl1.GetService<IUriProviderService>();
            if (service != null) {
                service.RegisterProvider(new CustomUriProvider());
        private void richEditControl1_ContentChanged(object sender, EventArgs e)

        private void ReloadHtml()
            HtmlDocumentExporterOptions exportOptions = new HtmlDocumentExporterOptions();
            exportOptions.EmbedImages = embedImagesCheck.Checked;
            string sText = richEditControl1.Document.GetHtmlText(richEditControl1.Document.Range, new CustomUriProvider(), exportOptions);
            memoEdit1.Text = sText;

This example implements the IUriProvider descendant and use it in the GetHtmlText(DocumentRange, IUriProvider, HtmlDocumentExporterOptions) method call.


The complete sample project How to save the document range in different formats is available in the DevExpress Examples repository.

public class CustomUriProvider : DevExpress.Office.Services.IUriProvider
    string rootDirectory;
    public CustomUriProvider(string rootDirectory)
        if (String.IsNullOrEmpty(rootDirectory))
            DevExpress.Office.Utils.Exceptions.ThrowArgumentException("rootDirectory", rootDirectory);
        this.rootDirectory = rootDirectory;

    public string CreateCssUri(string rootUri, string styleText, string relativeUri)
        string cssDir = String.Format("{0}\\{1}", this.rootDirectory, rootUri.Trim('/'));
        if (!Directory.Exists(cssDir))
        string cssFileName = String.Format("{0}\\style.css", cssDir);
        File.AppendAllText(cssFileName, styleText);
        return GetRelativePath(cssFileName);
    public string CreateImageUri(string rootUri, DevExpress.Office.Utils.OfficeImage image, string relativeUri)
        string imagesDir = String.Format("{0}\\{1}", this.rootDirectory, rootUri.Trim('/'));
        if (!Directory.Exists(imagesDir))
        string imageName = String.Format("{0}\\{1}.png", imagesDir, Guid.NewGuid());
        image.NativeImage.Save(imageName, ImageFormat.Png);
        return GetRelativePath(imageName);
    string GetRelativePath(string path)
        string substring = path.Substring(this.rootDirectory.Length);
        return substring.Replace("\\", "/").Trim('/');
See Also