Skip to main content

IUriStreamService.RegisterProvider(IUriStreamProvider) Method

Registers the Uri data stream provider and makes it available to clients of the service.

Namespace: DevExpress.Office.Services

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

NuGet Packages: DevExpress.Office.Core, DevExpress.Win.Navigation

Declaration

void RegisterProvider(
    IUriStreamProvider provider
)

Parameters

Name Type Description
provider IUriStreamProvider

An object which exposes the IUriStreamProvider interface.

Remarks

Use the RegisterProvider method to add a custom provider object that is used by a IUriStreamService service to retrieve data from the specified URI.

To obtain the data stream from the URI encountered in the document (such as an inline image or a calculated field with the corresponding switch) the RichEditControl accesses the IUriStreamService. The service processes the URI with the help of registered URI stream providers.

This implementation enables you to create and register a custom URI Stream provider that is capable of processing a custom URI in a specific way, for example, to retrieve images for the INCLUDEPICTURE field from a database.

This example demonstrates how to use the IUriStreamService.RegisterProvider method to register a custom data stream provider implementing the IUriStreamProvider interface and make it available to clients of the IUriStreamService service.

View Example

private void RegisterUriStreamService(RichEditControl richEditControl) {
    IUriStreamService uriStreamService = richEditControl.GetService<IUriStreamService>();
    uriStreamService.RegisterProvider(new ImageStreamProvider(NorthwindDataProvider.Categories, "Picture"));
}

View Example: Use Images When Implementing Mail Merge

This example demonstrates how to implement the IUriStreamProvider interface to create a custom data stream provider for the IUriProviderService service.

public class ImageStreamProvider : IUriStreamProvider {
    static readonly string prefix = "dbimg://";
    DataTable table;
    string columnName;

    public ImageStreamProvider(DataTable sourceTable, string imageColumn) {
        this.table = sourceTable;
        this.columnName = imageColumn;
    }


    public Stream GetStream(string uri) {
        uri = uri.Trim();
        if (!uri.StartsWith(prefix))
            return null;
        string strId = uri.Substring(prefix.Length).Trim();
        int id;
        if (!int.TryParse(strId, out id))
            return null;
        DataRow row = table.Rows.Find(id);
        if (row == null)
            return null;
        byte[] bytes = row[columnName] as byte[];
        if (bytes == null)
            return null;

        // Use this approach to trim the OLE header off the image
        // See also: https://supportcenter.devexpress.com/ticket/details/q233460/how-do-i-bind-a-pictureedit-to-sql-server-image-column, 
        // https://social.msdn.microsoft.com/Forums/en-US/c37289c7-3ca5-458e-8eda-286ffa2ff966/retrieving-an-image-from-a-table-in-a-c-picturebox?forum=sqldataaccess
        MemoryStream memoryStream = new MemoryStream();
        int oleHeaderOffset = 78;
        memoryStream.Write(bytes, oleHeaderOffset, bytes.Length - oleHeaderOffset);

        return memoryStream;
    }

The following code snippets (auto-collected from DevExpress Examples) contain references to the RegisterProvider(IUriStreamProvider) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also