The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

IUriStreamProvider.GetStream(String) Method

Provides the data stream for the specified Uri.

Namespace: DevExpress.Office.Services

Assembly: DevExpress.Office.v19.1.Core.dll

Declaration

Stream GetStream(string uri)
Function GetStream(uri As String) As Stream
Stream GetStream(string uri)
Function GetStream(uri As String) As Stream

Parameters

Name Type Description
uri String

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

Parameters

Name Type Description
uri String

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

Returns

Type Description
Stream

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

Returns

Type Description
Stream

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

Remarks

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.

Note

A complete sample project is available at: How to use images when implementing the mail-merge functionality

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: http://www.devexpress.com/issue=Q233460, 
        // http://social.msdn.microsoft.com/Forums/en-US/sqldataaccess/thread/c37289c7-3ca5-458e-8eda-286ffa2ff966/
        MemoryStream memoryStream = new MemoryStream();
        int oleHeaderOffset = 78;
        memoryStream.Write(bytes, oleHeaderOffset, bytes.Length - oleHeaderOffset);

        return memoryStream;
    }
See Also