Back to Devexpress

IUriProviderService Interface

officefileapi-devexpress-dot-office-dot-services-d43eac7f.md

latest5.3 KB
Original Source

IUriProviderService Interface

Represents a service that calls the registered IUriProvider interface when required.

Namespace : DevExpress.Office.Services

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

NuGet Package : DevExpress.Office.Core

Declaration

csharp
[ComVisible(true)]
public interface IUriProviderService
vb
<ComVisible(True)>
Public Interface IUriProviderService

Remarks

Create a class that implements the IUriProvider interface to enable specify custom locations for exported images and styles. Call the IUriProviderService.RegisterProvider method to register the target service.

View Example: Export to HTML - How to export only tag content and specify the location of CSS styles

Example

The following code snippet uses 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

csharp
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;
        }
vb
Imports DevExpress.Office.Services
Imports DevExpress.XtraRichEdit.API.Native
Imports DevExpress.XtraRichEdit.Export
Imports System
' ...
        Private Sub richEditControl1_DocumentLoaded(ByVal sender As Object, ByVal e As EventArgs) Handles richEditControl1.DocumentLoaded
            Dim service As IUriProviderService = richEditControl1.GetService(Of IUriProviderService)()
            If service IsNot Nothing Then
                service.RegisterProvider(New CustomUriProvider())
            End If
        End Sub

        Private Sub richEditControl1_ContentChanged(ByVal sender As Object, ByVal e As EventArgs)
            ReloadHtml()
        End Sub

        Private Sub ReloadHtml()
            Dim exportOptions As New HtmlDocumentExporterOptions()
            exportOptions.EmbedImages = embedImagesCheck.Checked
            Dim sText As String = richEditControl1.Document.GetHtmlText(richEditControl1.Document.Range, New CustomUriProvider(), exportOptions)
            memoEdit1.Text = sText
        End Sub
csharp
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;
        }
    }
vb
Imports DevExpress.Office.Services
Imports DevExpress.Office.Utils
Imports System
' ...
    Public Class CustomUriProvider
        Implements IUriProvider

        Public Function CreateCssUri(ByVal rootUri As String, ByVal styleText As String, ByVal relativeUri As String) As String Implements IUriProvider.CreateCssUri
            Return String.Empty
        End Function

        Public Function CreateImageUri(ByVal rootUri As String, ByVal image As OfficeImage, ByVal relativeUri As String) As String Implements IUriProvider.CreateImageUri
            Return image.Uri
        End Function
    End Class

See Also

IUriProviderService Members

DevExpress.Office.Services Namespace