none
Setting datasource for an existing rdlc report & print directly to printer RRS feed

  • Question

  • Hi Clever Gurus,

    My brain is frazzled from all the reading without success. I have a report AllPointsReport whose data is derived from a stored procedure. I'm able to print the report using the reportviewer. Now I've added functionality to filter the query & I need to print the filtered report to a pdf file (In some cases I will also email it)

    Viewing Report Data shows my datasources as "PointsHistory" & the datasets as "PointsDataSet1". Viewing the reportviewer frmAllPointsViewerRpt has the following code

        Private Sub InitializeComponent()
            Me.components = New System.ComponentModel.Container()
            Dim ReportDataSource1 As Microsoft.Reporting.WinForms.ReportDataSource = New Microsoft.Reporting.WinForms.ReportDataSource()
            Me.stpPointsHistoryReportDataBindingSource = New System.Windows.Forms.BindingSource(Me.components)
            Me.PointsHistory = New Sadta_Points_System.PointsHistory()
            Me.ReportViewer1 = New Microsoft.Reporting.WinForms.ReportViewer()
            Me.stpPointsHistoryReportDataTableAdapter = New Sadta_Points_System.PointsHistoryTableAdapters.stpPointsHistoryReportDataTableAdapter()
            CType(Me.stpPointsHistoryReportDataBindingSource, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.PointsHistory, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'stpPointsHistoryReportDataBindingSource
            '
            Me.stpPointsHistoryReportDataBindingSource.DataMember = "stpPointsHistoryReportData"
            Me.stpPointsHistoryReportDataBindingSource.DataSource = Me.PointsHistory
            '
            'PointsHistory
            '
            Me.PointsHistory.DataSetName = "PointsHistory"
            Me.PointsHistory.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema
            '
            'ReportViewer1
            '
            ReportDataSource1.Name = "PointsDataSet1"
            ReportDataSource1.Value = Me.stpPointsHistoryReportDataBindingSource
            Me.ReportViewer1.LocalReport.DataSources.Add(ReportDataSource1)
            Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "Sadta_Points_System.AllPointsReport.rdlc"
            Me.ReportViewer1.Location = New System.Drawing.Point(-5, 0)
            Me.ReportViewer1.Name = "ReportViewer1"
            Me.ReportViewer1.Size = New System.Drawing.Size(1066, 791)
            Me.ReportViewer1.TabIndex = 0
            '
            'stpPointsHistoryReportDataTableAdapter
            '
            Me.stpPointsHistoryReportDataTableAdapter.ClearBeforeFill = True

    Currently I have these fragments of code from my experimenting

    Dim lr As LocalReport = New LocalReport
    
                        'lr.ReportPath = "Sadta_Points_System.AllPointsReport.rdlc"
                        lr.ReportEmbeddedResource = "Sadta_Points_System.AllPointsReport.rdlc"
    
    Dim tadapt As PointsHistoryTableAdapters.stpPointsHistoryReportDataTableAdapter = New PointsHistoryTableAdapters.stpPointsHistoryReportDataTableAdapter
    
    Dim ds1 As ReportDataSource = New ReportDataSource("stpPointsHistoryReportData", ta1.Fill(dt))
    
    lr.DataSources.Add(ds1)
    
                        Dim warnings() As Warning
                        Dim streamids() As String
                        Dim mimeType As String
                        Dim encoding As String
                        Dim extension As String
                        Dim bytes() As Byte = lr.Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings)
                        'Dim s As MemoryStream = New MemoryStream(bytes)
                        's.Seek(0, SeekOrigin.Begin)
                        Dim savepath As String = "d:\rdlc_rep.pdf"
                        ' The FileStream class is in the System.IO namespace.
                        'Dim bytes() As Byte = Report.Render(fileType)
                        Dim fs As FileStream = New FileStream(savePath, FileMode.Create)
                        fs.Write(bytes, 0, bytes.Length)
                        fs.Close()
    
    

    Can somebody please help me put the correct bits together so I can get this to work. I think I'm at a point of too much info overload & can't figure it out.

    Sunday, November 11, 2018 1:49 PM

Answers

  • Hello,

    I am bit confused whether you want to print directly to printer <PDF Printer> or you want to export to PDF.

    What I have done is I have created two stored procedure one fetching all my data in table 'MySP' and another one fetching filtered data 'MyFilterSP' with single parameter @Para1

    on form load Report1.rdlc is bind with data returned by my first stored procedure MySP and on button click it first runs MyFilterSP <second stored procedure> then it binds report1.rdlc with the data returned by second stored procedure then It exports to PDF in D: drive and also it will print directly to printer without any preview

    Hope it helps you

    Imports System.Data.SqlClient
    Imports System.Data.Odbc
    Imports Microsoft.Reporting.WinForms
    Imports System.IO
    
    Public Class Form14
    
        Private Sub Form14_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            'TODO: This line of code loads data into the 'PointsHistory.MySP' table. You can move, or remove it, as needed.
            Me.MySPTableAdapter.Fill(Me.PointsHistory.MySP)
            Me.ReportViewer1.RefreshReport()
        End Sub
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Try
                Dim myConn As SqlConnection = New SqlConnection("Initial Catalog=TerminalDB;" & _
                        "Data Source=PGK_IDEAPAD\SQLSERVER2012;Integrated Security=True;")
                myConn.Open()
                Dim cmd As SqlCommand = New SqlCommand("MyFilterSP", myConn)
                Dim p As SqlParameter = New SqlParameter("@Para1", TextBox1.Text)
                cmd.Parameters.Add(p)
                cmd.CommandType = CommandType.StoredProcedure
                Dim rd As SqlDataReader = cmd.ExecuteReader()
                Dim dt As New DataTable
                dt.Load(rd)
                myConn.Close()
    
                ReportViewer1.LocalReport.DataSources.Clear()
                ReportViewer1.LocalReport.DisplayName = "Report1"
                ReportViewer1.LocalReport.ReportPath = "Report1.rdlc"
                Dim rds As ReportDataSource = New ReportDataSource("PointsDataSet1", dt)
                ReportViewer1.LocalReport.DataSources.Add(rds)
                Me.ReportViewer1.RefreshReport()
    
                'Export to PDF
                Dim bytes() As Byte
                Dim strDeviceInfo As String = ""
                Dim strMimeType As String = ""
                Dim strEncoding As String = ""
                Dim strExtension As String = ""
                Dim strStreams() As String
                Dim warnings() As Warning
                Dim oFileStream As FileStream
                Dim _stream As List(Of Stream) = New List(Of Stream)
                Try
                    bytes = Me.ReportViewer1.LocalReport.Render("PDF", strDeviceInfo, strMimeType, strEncoding, strExtension, strStreams, warnings)
    
                    oFileStream = New FileStream("D:\\Report1.pdf", FileMode.Create)
                    oFileStream.Write(bytes, 0, bytes.Length)
                    _stream.Add(oFileStream)
                Finally
                    If Not IsNothing(oFileStream) Then
                        oFileStream.Close()
                        oFileStream.Dispose()
                    End If
                End Try
    
                'Print 
                Dim obj As New PrintProgramatically
                obj.Run(Me.ReportViewer1.LocalReport)
    
            Catch ex As Exception
                Dim errormsg As String = String.Empty
                errormsg = ex.ToString()
            End Try
        End Sub
    End Class

    Imports System
    Imports System.IO
    Imports System.Data
    Imports System.Text
    Imports System.Drawing
    Imports System.Drawing.Imaging
    Imports System.Drawing.Printing
    Imports System.Collections.Generic
    Imports System.Windows.Forms
    Imports Microsoft.Reporting.WinForms
    Public Class PrintProgramatically
        Implements IDisposable
        Private m_currentPageIndex As Integer
        Private m_streams As IList(Of Stream)
    
        Private Function LoadSalesData() As DataTable
            ' Create a new DataSet and read sales data file 
            ' data.xml into the first DataTable.
            Dim dataSet As New DataSet()
            dataSet.ReadXml("..\..\data.xml")
            Return dataSet.Tables(0)
        End Function
    
        ' Routine to provide to the report renderer, in order to
        ' save an image for each page of the report.
        Private Function CreateStream(ByVal name As String, ByVal fileNameExtension As String, ByVal encoding As Encoding, ByVal mimeType As String, ByVal willSeek As Boolean) As Stream
            Dim stream As Stream = New MemoryStream()
            m_streams.Add(stream)
            Return stream
        End Function
    
        ' Export the given report as an EMF (Enhanced Metafile) file.
        Private Sub Export(ByVal report As LocalReport)
            Dim deviceInfo As String = "<DeviceInfo>" & _
                "<OutputFormat>EMF</OutputFormat>" & _
                "<PageWidth>8.5in</PageWidth>" & _
                "<PageHeight>11in</PageHeight>" & _
                "<MarginTop>0.25in</MarginTop>" & _
                "<MarginLeft>0.25in</MarginLeft>" & _
                "<MarginRight>0.25in</MarginRight>" & _
                "<MarginBottom>0.25in</MarginBottom>" & _
                "</DeviceInfo>"
            Dim warnings As Warning()
            m_streams = New List(Of Stream)()
            report.Render("Image", deviceInfo, AddressOf CreateStream, warnings)
            For Each stream As Stream In m_streams
                stream.Position = 0
            Next
        End Sub
    
        ' Handler for PrintPageEvents
        Private Sub PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
            Dim pageImage As New Metafile(m_streams(m_currentPageIndex))
    
            ' Adjust rectangular area with printer margins.
            Dim adjustedRect As New Rectangle(ev.PageBounds.Left - CInt(ev.PageSettings.HardMarginX), _
                                              ev.PageBounds.Top - CInt(ev.PageSettings.HardMarginY), _
                                              ev.PageBounds.Width, _
                                              ev.PageBounds.Height)
    
            ' Draw a white background for the report
            ev.Graphics.FillRectangle(Brushes.White, adjustedRect)
    
            ' Draw the report content
            ev.Graphics.DrawImage(pageImage, adjustedRect)
    
            ' Prepare for the next page. Make sure we haven't hit the end.
            m_currentPageIndex += 1
            ev.HasMorePages = (m_currentPageIndex < m_streams.Count)
        End Sub
    
        Private Sub Print()
            If m_streams Is Nothing OrElse m_streams.Count = 0 Then
                Throw New Exception("Error: no stream to print.")
            End If
            Dim printDoc As New PrintDocument()
            If Not printDoc.PrinterSettings.IsValid Then
                Throw New Exception("Error: cannot find the default printer.")
            Else
                AddHandler printDoc.PrintPage, AddressOf PrintPage
                m_currentPageIndex = 0
                printDoc.Print()
            End If
        End Sub
    
        ' Create a local report for Report.rdlc, load the data,
        ' export the report to an .emf file, and print it.
        Public Sub Run(ByVal report As LocalReport)
            Export(report)
            Print()
        End Sub
        Public Sub Dispose() Implements IDisposable.Dispose
            If m_streams IsNot Nothing Then
                For Each stream As Stream In m_streams
                    stream.Close()
                Next
                m_streams = Nothing
            End If
        End Sub
    End Class
    

    Sunday, November 11, 2018 3:53 PM
  • Hello,

    Check below code it should remove null reference error / green line.

    I have checked with Visibility Off at my end same code works let me know your observation with updated code

    'Export to PDF
                Dim bytes() As Byte
                Dim strDeviceInfo As String = ""
                Dim strMimeType As String = ""
                Dim strEncoding As String = ""
                Dim strExtension As String = ""
                Dim strStreams() As String = {}
                Dim warnings() As Warning = {}
                Dim oFileStream As New FileStream("D:\\Report1.pdf", FileMode.Create)
                Dim _stream As List(Of Stream) = New List(Of Stream)
                Try
                    bytes = Me.ReportViewer1.LocalReport.Render("PDF", strDeviceInfo, strMimeType, strEncoding, strExtension, strStreams, warnings)
    
                    oFileStream.Write(bytes, 0, bytes.Length)
                    _stream.Add(oFileStream)
                Finally
                    If Not IsNothing(oFileStream) Then
                        oFileStream.Close()
                        oFileStream.Dispose()
                    End If
                End Try

    Monday, November 12, 2018 11:28 AM

All replies

  • Hello,

    I am bit confused whether you want to print directly to printer <PDF Printer> or you want to export to PDF.

    What I have done is I have created two stored procedure one fetching all my data in table 'MySP' and another one fetching filtered data 'MyFilterSP' with single parameter @Para1

    on form load Report1.rdlc is bind with data returned by my first stored procedure MySP and on button click it first runs MyFilterSP <second stored procedure> then it binds report1.rdlc with the data returned by second stored procedure then It exports to PDF in D: drive and also it will print directly to printer without any preview

    Hope it helps you

    Imports System.Data.SqlClient
    Imports System.Data.Odbc
    Imports Microsoft.Reporting.WinForms
    Imports System.IO
    
    Public Class Form14
    
        Private Sub Form14_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            'TODO: This line of code loads data into the 'PointsHistory.MySP' table. You can move, or remove it, as needed.
            Me.MySPTableAdapter.Fill(Me.PointsHistory.MySP)
            Me.ReportViewer1.RefreshReport()
        End Sub
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Try
                Dim myConn As SqlConnection = New SqlConnection("Initial Catalog=TerminalDB;" & _
                        "Data Source=PGK_IDEAPAD\SQLSERVER2012;Integrated Security=True;")
                myConn.Open()
                Dim cmd As SqlCommand = New SqlCommand("MyFilterSP", myConn)
                Dim p As SqlParameter = New SqlParameter("@Para1", TextBox1.Text)
                cmd.Parameters.Add(p)
                cmd.CommandType = CommandType.StoredProcedure
                Dim rd As SqlDataReader = cmd.ExecuteReader()
                Dim dt As New DataTable
                dt.Load(rd)
                myConn.Close()
    
                ReportViewer1.LocalReport.DataSources.Clear()
                ReportViewer1.LocalReport.DisplayName = "Report1"
                ReportViewer1.LocalReport.ReportPath = "Report1.rdlc"
                Dim rds As ReportDataSource = New ReportDataSource("PointsDataSet1", dt)
                ReportViewer1.LocalReport.DataSources.Add(rds)
                Me.ReportViewer1.RefreshReport()
    
                'Export to PDF
                Dim bytes() As Byte
                Dim strDeviceInfo As String = ""
                Dim strMimeType As String = ""
                Dim strEncoding As String = ""
                Dim strExtension As String = ""
                Dim strStreams() As String
                Dim warnings() As Warning
                Dim oFileStream As FileStream
                Dim _stream As List(Of Stream) = New List(Of Stream)
                Try
                    bytes = Me.ReportViewer1.LocalReport.Render("PDF", strDeviceInfo, strMimeType, strEncoding, strExtension, strStreams, warnings)
    
                    oFileStream = New FileStream("D:\\Report1.pdf", FileMode.Create)
                    oFileStream.Write(bytes, 0, bytes.Length)
                    _stream.Add(oFileStream)
                Finally
                    If Not IsNothing(oFileStream) Then
                        oFileStream.Close()
                        oFileStream.Dispose()
                    End If
                End Try
    
                'Print 
                Dim obj As New PrintProgramatically
                obj.Run(Me.ReportViewer1.LocalReport)
    
            Catch ex As Exception
                Dim errormsg As String = String.Empty
                errormsg = ex.ToString()
            End Try
        End Sub
    End Class

    Imports System
    Imports System.IO
    Imports System.Data
    Imports System.Text
    Imports System.Drawing
    Imports System.Drawing.Imaging
    Imports System.Drawing.Printing
    Imports System.Collections.Generic
    Imports System.Windows.Forms
    Imports Microsoft.Reporting.WinForms
    Public Class PrintProgramatically
        Implements IDisposable
        Private m_currentPageIndex As Integer
        Private m_streams As IList(Of Stream)
    
        Private Function LoadSalesData() As DataTable
            ' Create a new DataSet and read sales data file 
            ' data.xml into the first DataTable.
            Dim dataSet As New DataSet()
            dataSet.ReadXml("..\..\data.xml")
            Return dataSet.Tables(0)
        End Function
    
        ' Routine to provide to the report renderer, in order to
        ' save an image for each page of the report.
        Private Function CreateStream(ByVal name As String, ByVal fileNameExtension As String, ByVal encoding As Encoding, ByVal mimeType As String, ByVal willSeek As Boolean) As Stream
            Dim stream As Stream = New MemoryStream()
            m_streams.Add(stream)
            Return stream
        End Function
    
        ' Export the given report as an EMF (Enhanced Metafile) file.
        Private Sub Export(ByVal report As LocalReport)
            Dim deviceInfo As String = "<DeviceInfo>" & _
                "<OutputFormat>EMF</OutputFormat>" & _
                "<PageWidth>8.5in</PageWidth>" & _
                "<PageHeight>11in</PageHeight>" & _
                "<MarginTop>0.25in</MarginTop>" & _
                "<MarginLeft>0.25in</MarginLeft>" & _
                "<MarginRight>0.25in</MarginRight>" & _
                "<MarginBottom>0.25in</MarginBottom>" & _
                "</DeviceInfo>"
            Dim warnings As Warning()
            m_streams = New List(Of Stream)()
            report.Render("Image", deviceInfo, AddressOf CreateStream, warnings)
            For Each stream As Stream In m_streams
                stream.Position = 0
            Next
        End Sub
    
        ' Handler for PrintPageEvents
        Private Sub PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
            Dim pageImage As New Metafile(m_streams(m_currentPageIndex))
    
            ' Adjust rectangular area with printer margins.
            Dim adjustedRect As New Rectangle(ev.PageBounds.Left - CInt(ev.PageSettings.HardMarginX), _
                                              ev.PageBounds.Top - CInt(ev.PageSettings.HardMarginY), _
                                              ev.PageBounds.Width, _
                                              ev.PageBounds.Height)
    
            ' Draw a white background for the report
            ev.Graphics.FillRectangle(Brushes.White, adjustedRect)
    
            ' Draw the report content
            ev.Graphics.DrawImage(pageImage, adjustedRect)
    
            ' Prepare for the next page. Make sure we haven't hit the end.
            m_currentPageIndex += 1
            ev.HasMorePages = (m_currentPageIndex < m_streams.Count)
        End Sub
    
        Private Sub Print()
            If m_streams Is Nothing OrElse m_streams.Count = 0 Then
                Throw New Exception("Error: no stream to print.")
            End If
            Dim printDoc As New PrintDocument()
            If Not printDoc.PrinterSettings.IsValid Then
                Throw New Exception("Error: cannot find the default printer.")
            Else
                AddHandler printDoc.PrintPage, AddressOf PrintPage
                m_currentPageIndex = 0
                printDoc.Print()
            End If
        End Sub
    
        ' Create a local report for Report.rdlc, load the data,
        ' export the report to an .emf file, and print it.
        Public Sub Run(ByVal report As LocalReport)
            Export(report)
            Print()
        End Sub
        Public Sub Dispose() Implements IDisposable.Dispose
            If m_streams IsNot Nothing Then
                For Each stream As Stream In m_streams
                    stream.Close()
                Next
                m_streams = Nothing
            End If
        End Sub
    End Class
    

    Sunday, November 11, 2018 3:53 PM
  • Hi there. Thanks for responding. Ultimately I need to do both. Print directly & also for another routine I need to export. I see your Form14 is the reportviewer form. I have a reportviewer form "frmAllPointsViewerRpt" which is fine to view the report on the screen then print if wanted. However I'm trying to print/export directly to printer from a different form. It could be an email form or a form from which I will select a report to be exported to pdf.

    Currently I call a routine which does a bunch of calculations outputting to some tables & the stored procedure query gets it all together for my report. The stored procedure has parameters passed to it to filter the data so I get only the data I need.

    I'm hoping to call the "AllPointsReport.rdlc" as a local report something like

    Dim lr As LocalReport = New LocalReport
    
                        lr.ReportEmbeddedResource = "Sadta_Points_System.AllPointsReport.rdlc"

    I'd like to avoid loading the reportviewer to load the report just to get the export. I also don't want to see the reportviewer. More than anything this part is what I'm not getting right

    Dim tadapt As PointsHistoryTableAdapters.stpPointsHistoryReportDataTableAdapter = New PointsHistoryTableAdapters.stpPointsHistoryReportDataTableAdapter
    
    Dim ds1 As ReportDataSource = New ReportDataSource("stpPointsHistoryReportData", ta1.Fill(dt))
    
    lr.DataSources.Add(ds1)

    On your 2nd code I don't have an xml file for the report so for me to use that I would have to generate one. Are you able to guide me on these 2 issues please?

    Sunday, November 11, 2018 9:15 PM
  • Hello,

    Your AllPointsReport.rdlc is nothing but XML file. My Code Exports to PDF & also Print to Printer directly on button click event with filtered data. If you dnt want report viewer to be visible make your report viewer much smaller with Visusbility OFF. 

    Monday, November 12, 2018 5:56 AM
  • Hi,

    Thanks for trying to help me. I have code as follows so far

                        Using conn As New SqlConnection(connString)
                            If conn.State = ConnectionState.Closed Then
                                conn.Open()
                            End If
    
                            Using com As SqlCommand = New SqlCommand("stpPointsHistoryReportData", conn)
                                com.CommandType = CommandType.StoredProcedure
    
                                Dim dr As SqlDataReader = com.ExecuteReader()
                                dt.Load(dr)
                                dr.Close()
                            End Using
                        End Using
    
                        Dim ReportViewer1 As New ReportViewer
                        ReportViewer1.LocalReport.DataSources.Clear()
                        ReportViewer1.LocalReport.DisplayName = "Report1"
                        ReportViewer1.LocalReport.ReportPath = "AllPointsReport.rdlc"
    
                        Dim rds As ReportDataSource = New ReportDataSource("PointsDataSet1", dt)
                        ReportViewer1.LocalReport.DataSources.Add(rds)
                        ReportViewer1.RefreshReport()
    
                        'Export to PDF
                        Dim bytes() As Byte
                        Dim strDeviceInfo As String = ""
                        Dim strMimeType As String = ""
                        Dim strEncoding As String = ""
                        Dim strExtension As String = ""
                        Dim strStreams() As String
                        Dim warnings() As Warning
                        Dim oFileStream As FileStream
                        Dim _stream As List(Of Stream) = New List(Of Stream)
    
                        Try
                            bytes = ReportViewer1.LocalReport.Render("PDF", strDeviceInfo, strMimeType, strEncoding, strExtension, strStreams, warnings)
    
                            oFileStream = New FileStream("D:\\Report1.pdf", FileMode.Create)
                            oFileStream.Write(bytes, 0, bytes.Length)
                            _stream.Add(oFileStream)
                        Finally
                            If Not IsNothing(oFileStream) Then
                                oFileStream.Close()
                                oFileStream.Dispose()
                            End If
                        End Try
    

    strStreams, warnings as well as oFileStream have the green line under & passed by reference before being assigned a value. A null reference.....

    When I run the code stepping through it errors out on line

    bytes = ReportViewer1.LocalReport.Render("PDF", strDeviceInfo, strMimeType, strEncoding, strExtension, strStreams, warnings)

    This line
    If Not IsNothing(oFileStream) Then

    goes straight to end if. Is this becaude the "frmAllPointsViewerRpt" is not opened? If so how do I open it with visible off?


    Monday, November 12, 2018 9:13 AM
  • Hello,

    Check below code it should remove null reference error / green line.

    I have checked with Visibility Off at my end same code works let me know your observation with updated code

    'Export to PDF
                Dim bytes() As Byte
                Dim strDeviceInfo As String = ""
                Dim strMimeType As String = ""
                Dim strEncoding As String = ""
                Dim strExtension As String = ""
                Dim strStreams() As String = {}
                Dim warnings() As Warning = {}
                Dim oFileStream As New FileStream("D:\\Report1.pdf", FileMode.Create)
                Dim _stream As List(Of Stream) = New List(Of Stream)
                Try
                    bytes = Me.ReportViewer1.LocalReport.Render("PDF", strDeviceInfo, strMimeType, strEncoding, strExtension, strStreams, warnings)
    
                    oFileStream.Write(bytes, 0, bytes.Length)
                    _stream.Add(oFileStream)
                Finally
                    If Not IsNothing(oFileStream) Then
                        oFileStream.Close()
                        oFileStream.Dispose()
                    End If
                End Try

    Monday, November 12, 2018 11:28 AM
  • Me again. I have them working. Thank you. I just need to adjust the margins as I'm getting some wraparound causing extra lines. (264 page report ends up 966 pages. Go figure) What I wanted to ask was can the margin setting be in metric ? ie 10mm or .1cm?

    What I did about the xml read was since I'm using a stored procedure, I'm already loading the data into a datatable so just returned the datatable. That won't cause me any problems will it?

    Thanks for your efforts. I can now move on with all the other parts I need to do using this.

    Monday, November 12, 2018 1:04 PM
  • I also found this method which uses the report rdlc directly

     Using conn As New SqlConnection(connString)
                            If conn.State = ConnectionState.Closed Then
                                conn.Open()
                            End If
    
                            Using com As SqlCommand = New SqlCommand("stpPointsHistoryReportData", conn)
                                com.CommandType = CommandType.StoredProcedure
    
                                Dim dr As SqlDataReader = com.ExecuteReader()
                                dt.Load(dr)
                                dr.Close()
                            End Using
                        End Using
    
                        Dim lr As LocalReport = New LocalReport
                        lr.ReportEmbeddedResource = "Sadta_Points_System.AllPointsReport.rdlc"
    
                        Dim rds As ReportDataSource = New ReportDataSource("PointsDataSet1", dt)
    
                        lr.DataSources.Add(rds)
    
                        Dim warnings() As Warning = {}
                        Dim streamids() As String = {}
                        Dim mimeType As String = Nothing
                        Dim encoding As String = Nothing
                                            
                        Dim reportName As String = "Report_rdlc"
    
                        Dim filenameExtension As String = "pdf"
                        Dim bytes() As Byte = lr.Render("PDF", Nothing, mimeType, encoding, filenameExtension, streamids, warnings)
                        Dim filename As String = Path.Combine("D:\", reportName)
                        'Dim filename As String = Path.Combine(Path.GetTempPath, reportName)
                        Dim fs = New FileStream(filename, FileMode.Create)
                        fs.Write(bytes, 0, bytes.Length)
                        fs.Close()
    
    Thanks to your help I got that to work as well so I have options going forward.

    Monday, November 12, 2018 1:18 PM
  • Glad it works......If need any help let me know
    Monday, November 12, 2018 1:21 PM