Question about OnExportReportResponse

Stimulsoft Reports.NET discussion
Post Reply
okamashev
Posts: 3
Joined: Tue Oct 30, 2018 3:36 pm

Question about OnExportReportResponse

Post by okamashev »

Hello!

As described in documentation: "To perform any actions with an already exported report, the OnExportReportResponse event is used. This event will be called immediately before the file is saved. In this event, you can get the export format, the type of the Web content and the name of the file to save. You can also get, and, if necessary, change the byte stream of the final export file."

I tried to change byte stream and it doesn't work for me (old stream saves).
My code is:

Code: Select all

  protected void Report_OnExportResponse(object sender, StiExportReportResponseEventArgs e)
        {
                Stream stream = e.Stream;
                var text = stream.ReadAll().Replace("A", "B");
                e.Stream = new MemoryStream(Encoding.UTF8.GetBytes(text ?? ""));
        }
Could you help me and say what is wrong?
Lech Kulikowski
Posts: 6238
Joined: Tue Mar 20, 2018 5:34 am

Re: Question about OnExportReportResponse

Post by Lech Kulikowski »

Hello,

You can use the following code:

Code: Select all

using (var reader = new StreamReader(e.Stream))
        {
            var text = reader.ReadToEnd().Replace("A", "B");
            var result = new MemoryStream(Encoding.UTF8.GetBytes(text ?? ""));
            e.Stream.Position = 0;
            e.Stream.SetLength(result.Length);
            result.CopyTo(e.Stream);
        }
Also, we have added this task to our to-do list.

Thank you.
okamashev
Posts: 3
Joined: Tue Oct 30, 2018 3:36 pm

Re: Question about OnExportReportResponse

Post by okamashev »

Thank you for answer

But this code returns error Exception Details: System.ObjectDisposedException: Cannot access a closed Stream.
I've tried to do somethig with StreamWriter but: Exception Details: System.ArgumentException: Stream was not writable.
Lech Kulikowski
Posts: 6238
Joined: Tue Mar 20, 2018 5:34 am

Re: Question about OnExportReportResponse

Post by Lech Kulikowski »

Hello,

We couldn't reproduce the issue in our samples.

Please send us a sample project which reproduces the issue for analysis.

Thank you.
okamashev
Posts: 3
Joined: Tue Oct 30, 2018 3:36 pm

Re: Question about OnExportReportResponse

Post by okamashev »

I'm sorry, everethyng works
Thank you very much
Lech Kulikowski
Posts: 6238
Joined: Tue Mar 20, 2018 5:34 am

Re: Question about OnExportReportResponse

Post by Lech Kulikowski »

Hello

We are always glad to help you!
Please let us know if you need any additional help.

Thank you.
Post Reply