Skip to main content
.NET Framework 4.5.2+

IUriStreamProvider.GetStream(String) Method

Provides the data stream for the specified Uri.

Namespace: DevExpress.Office.Services

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

NuGet Package: DevExpress.Office.Core


Stream GetStream(
    string uri


Name Type Description
uri String

A string specifying the URI of the object that is the source of the stream.


Type Description

A Stream object specifying a data stream or null (Nothing in Visual Basic).


If you register a custom Uri stream provider using the IUriStreamService.RegisterProvider method, its GetStream method is called when it is necessary to get data for the URI encountered in the document. It can provide data for external images represented by their URI or for the calculated fields.

For instance, you can use a custom URI provider to process a custom switch of the INCLUDEPICTURE field. Implement a GetStream method, so it retrieves images from a custom source specified by the value of a custom switch. This approach is illustrated in the ‘Merge Database Records’ demo shipped with installation.

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:, 
        MemoryStream memoryStream = new MemoryStream();
        int oleHeaderOffset = 78;
        memoryStream.Write(bytes, oleHeaderOffset, bytes.Length - oleHeaderOffset);

        return memoryStream;
See Also