locked
Saving Multiple Reports RRS feed

  • Question

  • User-1486682524 posted

    Hello,

    I am trying to save multiple reports at the same time using reportViewer.LocalReport.Render.   The report that is to be saved is currently determined by an id that is stored in session.  My idea is to save the first report then change the id in session, refresh the datasource and report, then print the second report and so on.  Here is an example of the code that I am trying to use:

    Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click

            Dim warnings As Warning() = Nothing
            Dim streamids As String() = Nothing
            Dim mimeType As String = Nothing
            Dim encoding As String = Nothing
            Dim extension As String = Nothing
            Dim bytes As Byte()
            Dim path As String = "C:\3\test.pdf"

            Session("ID") = 25
            odsRptSource.DataBind()
            reportViewer.LocalReport.Refresh()

            bytes = reportViewer.LocalReport.Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings)

            Session("ID") = 50
            odsRptSource.DataBind()
            reportViewer.LocalReport.Refresh()

            bytes += reportViewer.LocalReport.Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings)

            File.WriteAllBytes(path, bytes)
            
        End Sub

    The problem that I am running into is that the report does not seem to refresh when I include:

    bytes = reportViewer.LocalReport.Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings)

    It just prints the same report over and over.

    If I do not include:

    bytes = reportViewer.LocalReport.Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings)

    The report does show a new ID when I refersh.

    Thanks for any help,

    MxW

    Thursday, August 29, 2013 1:00 PM

Answers

  • User2103319870 posted

    Hi,

    With initial analysis what I can find from your code is your are using the same global variable( bytes) to hold the data.

    In that case variable will have the data of the last section of code (ie Session ID:50) even though data is refreshed properly in SSRS Report.

    One suggestion is to use different variables to hold the byte data.

    Please modify your code like given below

    Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
    
            Dim warnings As Warning() = Nothing
            Dim streamids As String() = Nothing
            Dim mimeType As String = Nothing
            Dim encoding As String = Nothing
            Dim extension As String = Nothing
            Dim bytes As Byte()
            Dim bytes1 As Byte()
            Dim path As String = "C:\3\test.pdf"
    
            Session("ID") = 25
            odsRptSource.DataBind()
            reportViewer.LocalReport.Refresh()
    
            bytes = reportViewer.LocalReport.Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings)
    
            File.WriteAllBytes(path, bytes)
    
            Session("ID") = 50
            odsRptSource.DataBind()
            reportViewer.LocalReport.Refresh()
    
            bytes1 += reportViewer.LocalReport.Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings)
    
            File.WriteAllBytes(path, bytes1)
            
            End Sub


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 29, 2013 8:33 PM