Skip to content

Display Text from a Blob Field in RDLC Report

December 23, 2011

With reference to my post i did yesterday and a question that came up an mibuso i found another great way to use the StreamReader Class of .Net for a simple NAV problem.

If you want to display text that is stored in binary format in a report you would need to use looping and reading the content of the blob piece for piece.

With .net Interop we can do this a lot better. The StreamReader class is ideal to handle this. It is capable to read the text inside the blob, detects the correct charset and gives us back the whole content with one method call.

Simply define a variable of type dotnet and subtype:

 mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.StreamReader

and you need a InStream Variable

Use this code to create an instance of the StreamReader:

IF ISSERVICETIER THEN BEGIN
  TempBlob.Blob.CREATEINSTREAM(IStream);
  StreamReader := StreamReader.StreamReader(IStream,TRUE);
END;

As Source Expression of the reports textbox (in classic section designer) you set the following:

StreamReader.ReadToEnd()

If the report still needs to be executable in classic client, set the textbox to visible = false.

In the RDLC Layout you can assign any textbox with the dataset field (set CanGrow = True to let it display the whole content).

Advertisements
15 Comments
  1. Guido Beikircher permalink

    The Code show good but don’t work – we got an error Message after we start the Report.

    The DotNet variable has not been instantiated:

    Code: OnPostDataItem

    TempBlob.INIT;
    TempBlob.Blob.CREATEOUTSTREAM(OStream);
    Test.WRITE(OStream);
    TempBlob.INSERT;

    IF ISSERVICETIER THEN BEGIN
    TempBlob.Blob.CREATEINSTREAM(IStream);
    StreamReader := StreamReader.StreamReader(IStream,TRUE);
    END;

    • Sad to hear it’s not working for you.

      Since the error said the var is not instantiated, but you clearly have it instanciated in your code you posted, there must be a timing problem.
      The variable is instantiated after you use it.

      My first guess would be that if you put the code in OnPostDataitem, it will be executed after the Read Method in the textbox variable, since it’s OnPost.
      I think you need to move the code, further up in the hirarchy, or place the textbox further down.
      Please let me know if this helped you.

      • Guido Beikircher permalink

        Hello devch
        we tried to move it upper in the hirarchy but it don’t work

        Reportsstruktur

        Job
        Structural Plan Line
        Job Ledger Entry (there is now the Code for the
        Streamreaer)
        Structural Plan Pos. Text Line

        #- CODE in OnAfterGetRecord

        IF ISSERVICETIER THEN BEGIN
        PosText.RESET;
        PostText.SETRANGE(Type,’QKS’);
        PosText.SETRANGE(“JSP Code”,LogEntry.”JSP Code”);
        IF PosText.FINDLAST THEN
        IF PosText.BLOB.HASVALUE THEN BEGIN
        PosText.BLOB.CREATEINSTREAM(IStream);
        StreamReader := StreamReader.StreamReader(IStream,TRUE);
        END;
        END;

        In the Section we put the StreamReader.ReadToEnd() in the Section of JobLedgEntry,TransFooter

        The VAR – StreamReader has as the Option RunOnClient / TRUE because the Service Tier runs on a seperate ServerMachine

        Best regard
        Guido

        • runonclient needs to be false! The dataset is generated on the service!

  2. Guido permalink

    Hello devch,

    now it’s works perfect – but we have store an RTF Text into the Database and the Report only shows the RTF Text not the formatet Text.
    Do you now any solution to solve this Problem – RTC-Report don’t have any Box like RTFTextbox.
    Best regard
    Guido

  3. Hi I tried to run the ejmplo commenting on this page but it has been possible to create it I get an error when trying to save and compile unknow type “. if someone can support me you’ll be thankful

    • Is it possible that you have copy & pasted the subtype directly from here? Then please try to select the System.IO.StreamReader manually from the dialog. If you then still have issues, I would check if a higher build fixes the issue. I would be interested in your build version anyway, please let us know which one you are using.
      Please share your sourcecode here too.

  4. Name DataType Subtype
    IStream InStream
    StreamReaderxps DotNet ‘mscorlib, Version=2.0.0.0, Culture=neutral, publicKeyToken=b77a5c561934e089’.System.IO.StreamReader
    TempBlob Record TempBlob
    rSalInvHeader Record Sales Invoices Header

    rSalInvHeader.CALCFIELDS(“Sales Invoice Header”.”Original String”);
    IF ISSERVICETIER THEN BEGIN
    rSalInvHeader.”Original String”.CREATEINSTREAM(IStream);
    StreamReaderxps := StreamReaderxps.StreamReader(IStream,TRUE); /// <– I get error in this line uknown Type ".
    StreamReaderxps.ReadToEnd()
    END;

    can guide me to solve this error, I appreciate your support
    Best regard

  5. Hi devch, I tried your solution in NAV2013 R2 and it worked great. But I am getting a small rectangle character printed at end of last line of text everytime in report printing

  6. Name permalink

    If you guys are having issue with small rectangular or space being added for nothing, go to http://stackoverflow.com/questions/37404789/display-blob-field-containing-text-in-rdlc-report-dynamics-nav/37405294#37405294

    got a solution there 😉

Trackbacks & Pingbacks

  1. Display Text from a Blob Field in RDLC Report | Pardaan.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s