Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

IUriProvider Interface

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

Namespace: DevExpress.Office.Services

Assembly: DevExpress.Office.v24.2.Core.dll

NuGet Package: DevExpress.Office.Core

#Declaration

[ComVisible(true)]
public interface IUriProvider

#Remarks

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 Identifiers (URI) for the external objects. The IUriProvider.CreateCssUri method processes the style information , and the IUriProvider.CreateImageUri processes images.

Tip

The SubDocument.GetHtmlText method has a parameter that is an object with the IUriProvider interface.

#Example

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.

View Example: Retain the Original Image URI in an HTML Document

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)
        {
            ReloadHtml();
        }

        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;
        }
using DevExpress.Office.Services;
using DevExpress.Office.Utils;
using System;
// ...
     public class CustomUriProvider : IUriProvider
     {
        public string CreateCssUri(string rootUri, string styleText, string relativeUri)
        {
            return String.Empty;
        }

        public string CreateImageUri(string rootUri, OfficeImage image, string relativeUri)
        {
            return image.Uri;
        }
    }
See Also