Skip to main content
All docs
V19.2
.NET Framework 4.5.2+

IUriProvider Interface

OBSOLETE

Please use the IUriProvider instead

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

Namespace: DevExpress.XtraRichEdit.Services

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

Declaration

[ComVisible(true)]
[Obsolete("Please use the DevExpress.Office.Services.IUriProvider instead", true)]
public interface IUriProvider :
    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 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.

Note

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

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

Note

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))
            Directory.CreateDirectory(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))
            Directory.CreateDirectory(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