none
Saving rdlc as PDF using reportviewer in a windows service RRS feed

  • Question

  • Hi All,

    I'm attempting migrate a windows service project written in VB from VS 05 into VS 08. The migration was successful however when testing the new app I cannot use the reportviewer.localreport.render command to save the PDF into a byte variable.

    The code i'm using is below and the exception messages i'm see are

    Inner exception 'An error has occurred during report processing.' source Microsoft.ReportViewer.Common

    Exception 'Value cannot be null. Parameter name: buffer'

     

    Private Function saveOrder(ByVal mode As Integer)
        Dim warnings As Warning() = Nothing, streamids As String() = Nothing, mimeType As String = Nothing
        Dim encoding As String = Nothing, extension As String = Nothing, bytes As Byte(), fileName As String
        Dim reportview As ReportViewer = New ReportViewer()
        Dim dd As Date = Now(), folder As String
    
        'build string to directory and create archive subfolder based on current date if it doesn't exist.
        folder = myset.SntOrdArchive & DatePart(DateInterval.Day, Now()) & "_" & DatePart(DateInterval.Month, dd) & "_" & DatePart(DateInterval.Year, dd) & "\"
    
        If Directory.Exists(folder) = False Then Directory.CreateDirectory(folder)
        'Add directory path to filename
        fileName = folder & OrderID & "_" & CustID & ".pdf"
    
        Dim fs As New FileStream(fileName, FileMode.Create)
        Dim w As New BinaryWriter(fs)
    
        Try
            reportview.LocalReport.ReportEmbeddedResource = "BatchReportTest.REP_OrderDSD.rdlc"
    
            reportview.LocalReport.DataSources.Add(New ReportDataSource("DataSet_CUSTOMER", Me.CustomerBindingSource))
            reportview.LocalReport.DataSources.Add(New ReportDataSource("DataSet_Order", Me.OrderBindingSource))
            reportview.LocalReport.DataSources.Add(New ReportDataSource("DataSet_OrderItems", Me.OrderItemsBindingSource))
            reportview.LocalReport.DataSources.Add(New ReportDataSource("DataSet_DISTRIBUTOR", Me.DistributorBindingSource))
            reportview.LocalReport.DataSources.Add(New ReportDataSource("DataSet_Rep", Me.RepBindingSource))
            reportview.LocalReport.DataSources.Add(New ReportDataSource("DataSet_Calls", Me.CallsBingSource))
    
            If Me.DataSet.OrderItems.Rows.Count > 0 Then
                Try
                    bytes = reportview.LocalReport.Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings)
                Catch e As System.Exception
                    MsgBox("Inner: " & e.InnerException.Message & vbCrLf _
                           & e.InnerException.Source)
                End Try
    
                w.Write(bytes)
                w.Flush()
            End If
    
            w.Close()
            fs.Close()
            fs.Dispose()
            reportview.Dispose()
        Catch ex As Exception
    
            MsgBox("" & ex.Message)
            fileName = "Fail"
            w.Flush()
            w.Close()
            fs.Close()
            fs.Dispose()
            reportview.Dispose()
        End Try
    
        bytes = Nothing
        Return fileName
    End Function
    

     

    Friday, May 6, 2011 5:27 AM

All replies

  • The rendering code appears to be ok... Although an unusual name, could it be there is a report parameter called "buffer" that you need to add (localReport.SetParameters) ?
    Friday, May 6, 2011 10:09 AM